Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.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_Uitableview - Fatal编程技术网

Iphone 保存表格视图的状态/保存表格视图文本的状态

Iphone 保存表格视图的状态/保存表格视图文本的状态,iphone,objective-c,ios,uitableview,Iphone,Objective C,Ios,Uitableview,我有一个UITableView,可以添加和删除单元格。我在每个单元格上都有两个按钮,可以在单元格文本中添加和减去1。但是,当我转到另一个页面,然后返回到表视图页面时,所有单元格文本都被设置回1。但我希望单元格的文本保持在用户设置的值!有人能帮我吗?我不知道该怎么办。谢谢 您必须维护保存单元格值的NSMutableArray(可能是NSIntegers)。然后,每当用户更改值时,更新数组中的值。另外,通过从数组中读取来显示单元格标签值。下面是示例代码- -(void)plusButtonClick

我有一个UITableView,可以添加和删除单元格。我在每个单元格上都有两个按钮,可以在单元格文本中添加和减去1。但是,当我转到另一个页面,然后返回到表视图页面时,所有单元格文本都被设置回
1
。但我希望单元格的文本保持在用户设置的值!有人能帮我吗?我不知道该怎么办。谢谢

您必须维护保存单元格值的
NSMutableArray
(可能是
NSIntegers
)。然后,每当用户更改值时,更新数组中的值。另外,通过从数组中读取来显示单元格标签值。下面是示例代码-

-(void)plusButtonClicked:(id)sender
{ 
    //figure out the cell index which was updated using sender
    //update the array entry
    //[self.array objectAtIndex:index]++; self.array is the array you will maintain
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    cell.label.text = [NSString stringWithFormat: @"%d", [self.array objectAtIndex:indexPath.row]];
}

如果您希望即使在应用程序被终止并重新启动之后,这些值仍然存在,请考虑使用CordaDAT.

,您知道如何使用核心数据保存表视图状态的一个好教程吗?我已经搜索过了,但找不到任何有用的东西!谢谢你的帮助!