【发布时间】:2025-12-30 11:10:06
【问题描述】:
tableview的最后一行有一个按钮,当按下它时,我希望该行中的按钮消失,同时添加更多行,然后按钮再次出现在最后一行。 但我不知道怎么做! 这是我的代码:
- (void)morePicture:(id)sender{
NSMutableArray *indexpath = [[NSMutableArray alloc] init];
[photos removeObjectAtIndex:[photos count]-1];
[indexpath addObject:[NSIndexPath indexPathForRow:[photos count]+1 inSection:0]];
[table beginUpdates];
[table deleteRowsAtIndexPaths:indexpath withRowAnimation:UITableViewRowAnimationNone];
NSMutableArray *indexPathss = [[NSMutableArray alloc] init];
for(int i=0; i<3; i++){
NSString *s = [[NSString alloc] initWithFormat:@"%d",i];
[photos addObject:s];
NSIndexPath *indexpath = [NSIndexPath indexPathForRow:i inSection:0];
[indexPathss addObject:indexpath];
}
【问题讨论】:
-
这段代码对你有用吗?如果
photos是您的数据源,那么您似乎正在尝试删除 indexPath 行中大于源中项目数的行([photos count]+1应该是[photos count])。 -
如果按钮始终是表格中的最后一项,则将其放在表格的页脚视图中可能会更容易。这样它就会一直在底部。
标签: iphone ios xcode uitableview