Reputation:
I want to replay an alertView with textfield until it will be canceled. The text in the textfield should be save in a NSMutableArray
. I tried something, but it doesn't work. It will say by myNSMutableArray = ...
EXPECTED identifier. What am I doing wrong?
@synthesize myNSMutableArray;
- (void)viewDidLoad {
[super viewDidLoad];
[self alert];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex {
if (buttonIndex == 0) {
myNSMutableArray = [[NSMutableArray alloc] addObject:[[alertView textFieldAtIndex:0].text]];
[self alert];
}
else{
NSLog(@"Done");
}
}
-(void)alert{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Titel" message:@"Message" delegate:self cancelButtonTitle:@"Next" otherButtonTitles:@"Done", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[[alert textFieldAtIndex:0] setPlaceholder:@"First"];
[alert show];
}
Upvotes: 0
Views: 71
Reputation: 119031
You have a number of issues and demi-issues:
Remove the @synthesize
, you should pretty much never be using that now. You need to create the array in advance rather than repeatedly creating and not initialising it (thus destroying the previous object). And you have too many brackets around the text field usage when you're using dot notation.
Remember, if you have issues with a line of code compiling, break it out into parts so you can see which bit really has the issue and your code is easier to follow through.
- (void)viewDidLoad {
[super viewDidLoad];
self.myNSMutableArray = [NSMutableArray array];
[self alert];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
[self.myNSMutableArray addObject:[alertView textFieldAtIndex:0].text];
[self alert];
}
else{
NSLog(@"Done");
}
}
-(void)alert {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Titel" message:@"Message" delegate:self cancelButtonTitle:@"Next" otherButtonTitles:@"Done", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[[alert textFieldAtIndex:0] setPlaceholder:@"First"];
[alert show];
}
Upvotes: 3