Ali*_*Ali 6 iphone cocoa-touch objective-c
我在uinavigationbar上添加了一个按钮,我想用它来清除uitablview的所有行
我怎样才能做到这一点?
joa*_*oao 12
有点晚了......但试试这个:
你想要清除表格的地方:
// clear table
clearTable = YES;
[table reloadData];
clearTable = NO;
Run Code Online (Sandbox Code Playgroud)
此功能应如下所示:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(clearTable)
return 0;
(...)
}
Run Code Online (Sandbox Code Playgroud)
清除行到底是什么意思?您仍然希望它们在那里,但没有文字吗?如果是的话,代码如下:
UITableViewCell *cell;
NSIndexPath *index;
for (int i = 0 ; i < count; i++) {
index = [NSIndexPath indexPathForRow:i inSection:0];
cell = [tableView cellForRowAtIndexPath:index];
cell.textLabel.text = @"";
}
Run Code Online (Sandbox Code Playgroud)
如果你想删除它们,可以使用以下代码:
[uiTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationFade];
Run Code Online (Sandbox Code Playgroud)