NSString to string from GUI

Hi,

This is probably simple but I can’t find any examples or answers on here.

I am trying to use a text field and send that NSString to a string in a different .mm file. I have tried using

myApp = (testApp*)ofGetAppPtr();

seatValue = myApp->seat;

seatValue is the NSString and trying to send it to the testApp.h string seat.

Any help would be very grateful

Thanks

You can use the functions ofxNSStringToString(string) and ofxStringToNSString(string) to convert from a NSString to a string and vice versa.

Hi Seth,

Thanks for that another quick question you might be able to solve.

I have this

  
- (IBAction)hide:(id)sender {  
      
    rowTextField = (UITextField *)sender;    
    NSString *rowNumber = [[NSString alloc]initWithFormat:rowTextField.text];    
    rowTextField.text = rowNumber;    
    [rowNumber release];   
      
    rowValue = ofxNSStringToString(rowNumber);  
      
    rowValue = myApp->row;  
     
    self.view.hidden = YES;  
      
  
}  

But when I run it and press the button “hide” I get this.

UIApplicationMain(nil, nil, nil, @“ofxiPhoneAppDelegate”); // this will run the infinite loop checking all events

Any idea on what I am doing wrong? Is there somewhere else I should be putting that rather then in the IBAction for the button?

Thanks,
Nick

I don’t see where you define rowValue.

Instead just do:

  
myApp->row = ofxNSStringToString(rowNumber);  

rowValue is just a string defined in the .h file

Ill give it a go

It didn’t work still comes up with the same error.

The IBAction is a UIButton which is supposed to get me the value of the UITextField and then remove the current view.

when I get rid of the UITextField Stuff I don’t get the error and it does rome the view so I know its not that part of it.

It’s hard to say without seeing all your code. For example, do you define rowTextField earlier somewhere? If not, then it’ll crash there because it’s undefined.

I’m not sure your code makes sense because you’re getting the rowTextField text into rowNumber, but then you’re setting that same text back to rowTextField.text. If all you want is to get the sender’s text and send it to your myApp, I think it would look like the following.

  
- (IBAction)hide:(id)sender {    
        
    UITexField * rowTextField = sender;      
      
    myApp->row = ofxNSStringToString(rowTextField.text);    
       
    self.view.hidden = YES;      
}   

I feel like an idiot I have been trying that all day all i needed was

myApp->row = ofxNSStringToString(rowTextField.text);

because I had declared it earlier.

Thanks for your help

Any easy way to change a string to a int without doing a big array? While I have brain here

For converting string to int, check here: http://www.cplusplus.com/forum/general/13135/