Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 向数组动态添加和保存条目_Iphone_Objective C_Ios_Xcode - Fatal编程技术网

Iphone 向数组动态添加和保存条目

Iphone 向数组动态添加和保存条目,iphone,objective-c,ios,xcode,Iphone,Objective C,Ios,Xcode,我有一个包含项目列表的UITableView。如果我添加了一个新项目,它将被添加到列表中,但如果我移动到其他视图,它将消失。我希望它像那样保存,如果我们删除它,它应该被永久删除。我从plist那里得到了物品清单 NSString *fileForCategoryList = [[NSBundle mainBundle] pathForResource:kCATEGORY_LIST ofType:kP_List]; self.arrayForCategories = [[NSMutableArra

我有一个包含项目列表的UITableView。如果我添加了一个新项目,它将被添加到列表中,但如果我移动到其他视图,它将消失。我希望它像那样保存,如果我们删除它,它应该被永久删除。我从plist那里得到了物品清单

NSString *fileForCategoryList = [[NSBundle mainBundle] pathForResource:kCATEGORY_LIST ofType:kP_List];
self.arrayForCategories = [[NSMutableArray alloc]initWithContentsOfFile:fileForCategoryList];
这就是我编辑列表的方式

- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView  editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 
{
// No editing style if not editing or the index path is nil.
if (self.editing == NO || !indexPath) return UITableViewCellEditingStyleNone;
// Determine the editing style based on whether the cell is a placeholder for adding content or already 
// existing content. Existing content can be deleted.    
if (self.editing && indexPath.row == ([self.arrayForCategories count])) 
{
    return UITableViewCellEditingStyleInsert;
} 
else 
{
    return UITableViewCellEditingStyleDelete;
}
return UITableViewCellEditingStyleNone;
}

// Update the data model according to edit actions delete or insert.
- (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:@"Cancel" 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];
}   

在应用程序代理中获取一个数组。如果要添加任何项目,请将其添加到应用程序代理的数组中。也可以使用相同的数组进行删除。

这有助于将项目动态添加到数组中吗??