私はカテゴリのリストを持つテーブルビューを持っています。ユーザーが追加ボタンをタップすると、テキストフィールドと「OK」ボタンが表示されます。テキストフィールドに入力されたテキストがテーブルビューに追加されます。追加することはできますが、plist.soには追加されません私たちが別のビューに移動して戻ってくると、それはちょうど消えてしまいます。動的に入力されたデータをplistに保存する
-(void)viewDidLoad
{
NSString *fileForCategoryList = [[NSBundle mainBundle] pathForResource:kCATEGORY_LIST ofType:kP_List];
self.arrayForCategories = [[NSMutableArray alloc]initWithContentsOfFile:fileForCategoryList];
}
- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[self.arrayForCategories removeObjectAtIndex:indexPath.row];
[self.tableViewC reloadData];
}
else if (editingStyle == UITableViewCellEditingStyleInsert)
{
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:kYOUR_TITLE message:kEMPTY delegate:self cancelButtonTitle:kCANCEL otherButtonTitles:kOK, nil];
self.myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[self.myTextField setBackgroundColor:[UIColor whiteColor]];
[myAlertView addSubview:self.myTextField];
[myAlertView show];
[myAlertView release];
}
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if ([self.myTextField text])
{
[self.arrayForCategories addObject:[self.myTextField text]];
}
[self.tableViewC reloadData];
}
少しのコードやリンクを教えていただけますか? – Chandu
私の更新された答えを確認してください – visakh7
ya thanxは、リンクを試してみます。 – Chandu