作者kiii210 (Johnny.T)
看板MacDev
标题Re: [问题] UITableView动态增加资料
时间Thu May 23 00:59:56 2013
错了,
insertRowsAtIndexPaths:withRowAnimation:
Inserts rows in the receiver at the locations identified by an array
of index paths, with an option to animate the insertion.
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths
withRowAnimation:(UITableViewRowAnimation)animation
Parameters
indexPaths
--> An array of NSIndexPath objects each representing a row
--> index and section index that together identify a row in the table view.
这个method是要让你在指定的indexPath插入资料,
indexPaths这个阵列应该要是 NSIndexPath的阵列,
你的dataArray应该是tableView的dataSource...,
先在source插入资料没错,但是下一步要做的是把 NSIndexPath 用 NSArray 封装起来
int count = [dataArray count];
NSIndexPath indexPath = [NSIndexPath indexPathForRow:count-2 section:0]
NSArray *array = [NSArray arrayWithObject:indexPath];
[tableView insertRowsAtIndexPaths:array withRowAnimation:blablabla];
这样的code即是在倒数第二个row插入你要的资料~
以上是之前开发的经验,有说错还请板上各位纠正~~!
※ 引述《siriuschill (siriuschill)》之铭言:
: 我想自定一个Button
: 点击下去後
: tableview会自动增加一行
: 上网找了好多资料
: 都是在navigation上点击实现
: 有尝试过写到Button里
: 还是不行
: [self.tableView reloadData]
: 还是不能刷新
: 请问各位大大
: 我是不是漏了什麽动作呢?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 111.248.95.215
1F:→ Piceman:正解 05/23 01:02
3F:→ kiii210:你还是把完整的code贴上来好了 05/23 11:56
4F:→ yuanruo:看来我写的你没看到.. 05/23 12:51
6F:→ siriuschill:yuanruo大大 我有把reloadData拿掉过 不过还是不行 05/23 15:59
8F:→ yuanruo:我把你整段程式码call过来 原因在你beginupdate写错地方 05/23 20:03
9F:→ yuanruo:执行insertRowAtIndexPaths 你不加begin end 和reloadData 05/23 20:04
10F:→ yuanruo:以你的例子 都去掉就ok了 05/23 20:04
11F:→ yuanruo:你要写beginUpdate 要写在insert上面 完了後再endUpdate 05/23 20:05
12F:推 siriuschill:非常感谢yuanruo大大,把那2行拿掉後就解决了(^o^) 05/23 22:15
13F:→ kiii210:竟然被m了....@@ 05/31 08:47