テキストフィールドを備えたアラートビューがあるため、誰かが入力して保存ボタンを押すと、テーブルビューに表示されます。保存後にセルをクリックすると、別のビューに移動します。ホームページに戻ると、セルが消えます。私はそれを理解するために複数の方法を試しましたが、まだできていません。セルを追加するたびに plist に保存されるように、plist を追加する必要がありますか?
このコードは私のテーブルビューコントローラーにあります
- (IBAction)add:(id)sender {
NSLog(@"%@",tableData);
UIAlertView* alert=[[UIAlertView alloc] initWithTitle:@"My Favs" message:@"Hello" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Save", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField * alertTextField = [alert textFieldAtIndex:0];
alertTextField.enablesReturnKeyAutomatically = YES;
alertTextField.placeholder = @"example";
[alert show];
return;
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"%@",tableData);
//Only do the following action if the user hits the ok button
if (buttonIndex == 1){
NSString *tapTextField = [alertView textFieldAtIndex:0].text;
if (!tableData)
{
tableData = [[NSMutableArray alloc]init];
}
[tableData insertObject:tapTextField atIndex:0];
[myTableView reloadData];
}
}