0

How can I populate an empty but initialized array via text input?

I want the + button in the navbar to bring up a UIAlert prompting for a text. This text will then be stored in the array.

How would I go about this?

2 Answers 2

1

For initialize:

NSMutableArray * array = [[NSMutableArray alloc] init];

for populating:

[array addObject:textfied.text];
Sign up to request clarification or add additional context in comments.

Comments

0

i think u can save that text in the nsstring.

but if u want to save the text in nsarry then u can do this

 NSArray *data= [[NSArray alloc] initWithObjects:textField.text,nil];

and in order to save data in already declared nsarry then u can do this. if ur array is @property and syntesized

NSArray *data= [[NSArray alloc] initWithObjects:textField.text,nil];
 self.urArray=data;
 [data release];

14 Comments

I actually think I may need to store it in a dictionary. The plist needs to be an array of dictionarys I think.
thanks Iqbal. the problem is not populating the array, because I know how to do that, but it is how to populate using the text from a prompt that the user has to type in
Thanks iqbal. One last question though. I got the prompt working when I put the code in my ViewDidLoad. But how can I assign it to alert when I click the + button in my navbar? right now the + button is set to nil for the @selector.
how u r creating the + button. if in interface builder then simply declare a function in header and implementaion class and then link it.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.