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
Ios UITableView行插入、删除、更新_Ios_Objective C_Uitableview - Fatal编程技术网

Ios UITableView行插入、删除、更新

Ios UITableView行插入、删除、更新,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我正在创建一个ios应用程序,其中我希望在UITableView的顶部添加每一行,但不应删除已存在的行 例如,我在第1行中有一个单元格,当我单击它时,它将显示图像。即使我们在第1行中插入新单元格并将旧单元格移动到第2行,也应显示相同的图像 我在stackoverflow中搜索过,但我不明白他们解释了什么。因此,任何人都可以提供在ios中插入、删除和更新UITableView中的行的教程或示例应用程序 提前感谢。当您添加新单元格时,请在零索引上插入单元格数据,如下所示 NSMutableArray

我正在创建一个ios应用程序,其中我希望在
UITableView
的顶部添加每一行,但不应删除已存在的行

例如,我在第1行中有一个单元格,当我单击它时,它将显示图像。即使我们在第1行中插入新单元格并将旧单元格移动到第2行,也应显示相同的图像

我在stackoverflow中搜索过,但我不明白他们解释了什么。因此,任何人都可以提供在ios中插入、删除和更新
UITableView
中的行的教程或示例应用程序


提前感谢。

当您添加新单元格时,请在零索引上插入单元格数据,如下所示

NSMutableArray *dataArray = [[NSMutableArray alloc]initWithObjects:@"Hello",@"How Are You", nil]; 

// It's your data array that you have already allocation in viewDidLoad or some where else.. 


[dataArray insertObject:@"Joy" atIndex:0];  // Try this line on add there your are adding new cell data

[tableView beginUpdates];
NSIndexPath *indexpath = [NSIndexPath indexPathforRow:0 inSection:0];
NSArray *indextoadd = [NSArray arrayWithObject:indexpath1];
[tableView insertRowsAtIndexPaths:indextoadd withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView endUpdates];
使用此数组将自动排序,“Joy”名称将插入零索引,数组将自动移位

在此之后,重新加载tableview

[tableviewObj reloadData];
试试这个,希望你会成功。以表格为例

  • 要删除行,请选中它
  • 要更新行,请检查它

    在“重新加载前更新”中,在数组中替换表日期

    [dataArray replaceObjectAtIndex:index with object:newObject]

这三种方法可用于删除、插入和更新表行。
这里是Apple代码InsertRowatineXpath

如果它解决了您的问题,请接受答案…删除和更新如何我已经更新了我的答案检查它…但是使用插入代码,它在表的底部添加了行,而不是第一行,但我已经测试过了,它在数组的零索引上添加,那么它如何在最后显示。。。
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;