She*_*lam 1 iphone cocoa-touch objective-c uitableview ipad
我试图每隔30秒用新单元刷新一个UITableView.我的数组包含30个元素,对于我添加到数组中的每个新项目,我想删除表格中的最后一个单元格.我该怎么做呢?
要每30秒刷新一次,请使用NSTimer.
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:30
target:self selector:@selector(refreshTable)
userInfo:nil repeats:YES];
Run Code Online (Sandbox Code Playgroud)
在你的新增项目中添加-refreshTable.确保您的dataSource和表格同步.
-(void)refreshTable {
...
// modify the data source.
[items removeLastObject];
[items insertObject:newItem atIndex:0];
// modify the table.
[tableView beginUpdates];
[tableView insertRowsAtIndexPaths:
[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]]
withRowAnimation:withRowAnimation:UITableViewRowAnimationRight];
[tableView deleteRowsAtIndexPaths:
[NSArray arrayWithObject:[NSIndexPath indexPathForRow:29 inSection:0]]
withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
...
}
Run Code Online (Sandbox Code Playgroud)
有关如何执行批量插入和删除的信息,请参阅适用于iPhone OS的表视图编程指南.
| 归档时间: |
|
| 查看次数: |
3756 次 |
| 最近记录: |