iPhone SDK - convert strings to call variable names
Ok, I got used to coding with PHP. I'm currently trying to do a sudoku app. Now I'm coming to a point where I need to show the proper number in the appropriate cell (UITextfield) based on the number pressed. (I have 9 buttons that correspond to 1-9 respectively)
Conceptually when the used clicks on a cell, I want to: 1. put the UITextField name and put it in a string so that 2. when a user clicks on the number I tell the computer "Ok, put this number in (refer to our string variable) this cell"
I'm basically more concerned of paragraph 2. I've come upon开发者_C百科 this problem several times. In php, all we need is put a $ sign, concatenate strings then it'll be considered a variable. I'm wondering what the similar process for it in iphone sdk.
Please and thank you folks
Just set a pointer.
Objective-C is less like PHP and more like all the languages where you have to declare your variable at some point:
int myNumber = 9;
NSString *fieldText = @"Number:";
NSString *appendedText = [fieldText stringByAppendingFormat: @"%@ %d", myNumber];
It's also much more wordy :-)
精彩评论