Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.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
Iphone 如何在tableview中删除最后一行并添加更多行?_Iphone_Ios_Xcode_Uitableview - Fatal编程技术网

Iphone 如何在tableview中删除最后一行并添加更多行?

Iphone 如何在tableview中删除最后一行并添加更多行?,iphone,ios,xcode,uitableview,Iphone,Ios,Xcode,Uitableview,在tableview的最后一行中有一个按钮,当按下它时,我希望该行中的按钮消失,同时添加更多行,然后,该按钮再次出现在最后一行中。 但我不知道怎么做! 这是我的密码: - (void)morePicture:(id)sender{ NSMutableArray *indexpath = [[NSMutableArray alloc] init]; [photos removeObjectAtIndex:[photos count]-1]; [indexpath addObject:[NSInde

在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];
}
-(无效)更多图片:(id)发件人{
NSMutableArray*indepath=[[NSMutableArray alloc]init];
[照片移除对象索引:[照片计数]-1];
[indexpath addObject:[NSIndexPath indexPathForRow:[photos count]+1个分区:0]];
[表格开始更新];
[表deleteRowsAtIndexPaths:indexpath with RowAnimation:UITableViewRowAnimationNone];
NSMutableArray*indexpath=[[NSMutableArray alloc]init];

对于(int i=0;i您不需要调用
deleteRowsAtIndexPaths
方法。改用
insertRowsAtIndexPaths
。只需在最后一行按钮上方添加行,不要删除它

NSArray *newPhotos = ....;
NSMutableArray *photos = ...;

// insert new photos first (before table update)
[photos insertObjects:newPhotos atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange([photos count] - 1, [newPhotos count])];

NSMutableArray *newIndices = [NSMutableArray array];
for (NSInteger row = [photos count] - [newPhotos count] - 1; row < [photos count] - 1; row++) {
    [newIndices addObject:[NSIndexPath indexPathWithIndex:row];
}
[self.tableView insertRowsAtIndexPaths:newIndices withRowAnimation:UITableViewRowAnimationFade];
NSArray*newPhotos=。。。。;
NSMutableArray*照片=。。。;
//先插入新照片(表更新前)
[照片插入对象:索引中的新照片:[NSIndexSet IndexetWithindexInRange:NSMakeRange([photos count]-1,[newPhotos count]);
NSMutableArray*新索引=[NSMutableArray];
对于(NSInteger行=[photos count]-[newPhotos count]-1;行<[photos count]-1;行++){
[NewIndexes addObject:[NSIndexPath indexPathWithIndex:row];
}
[self.tableView insertRowsAtIndexPaths:newindex with rownanimation:uitableview rownanimationfade];

您不需要调用
deleteRowsAtIndexPaths
方法。改用
插入RowsatindExpaths
。只需在最后一行按钮上方添加行,不要删除它

NSArray *newPhotos = ....;
NSMutableArray *photos = ...;

// insert new photos first (before table update)
[photos insertObjects:newPhotos atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange([photos count] - 1, [newPhotos count])];

NSMutableArray *newIndices = [NSMutableArray array];
for (NSInteger row = [photos count] - [newPhotos count] - 1; row < [photos count] - 1; row++) {
    [newIndices addObject:[NSIndexPath indexPathWithIndex:row];
}
[self.tableView insertRowsAtIndexPaths:newIndices withRowAnimation:UITableViewRowAnimationFade];
NSArray*newPhotos=。。。。;
NSMutableArray*照片=。。。;
//先插入新照片(表更新前)
[照片插入对象:索引中的新照片:[NSIndexSet IndexetWithindexInRange:NSMakeRange([photos count]-1,[newPhotos count]);
NSMutableArray*新索引=[NSMutableArray];
对于(NSInteger行=[photos count]-[newPhotos count]-1;行<[photos count]-1;行++){
[NewIndexes addObject:[NSIndexPath indexPathWithIndex:row];
}
[self.tableView insertRowsAtIndexPaths:newindex with rownanimation:uitableview rownanimationfade];

UIButton*moreButton=[[UIButton alloc]initWithFrame:frame]

[moreButton setImage:[UIImage ImageName:@“button_signin.png”]用于状态:UIControlStateNormal]

[moreButton addTarget:self action:@selector(showMoreRows)for ControlEvents:UIControlEventTouchUpInside]

//将按钮添加到表页脚视图

self.tableView.tableFooterView=moreButton

在方法上

-(iAction)showMoreRows{

//在数组中添加对象,该对象负责创建表视图,然后调用

[self.tableView重载数据]


}UIButton*moreButton=[[UIButton alloc]initWithFrame:frame]

[moreButton setImage:[UIImage ImageName:@“button_signin.png”]用于状态:UIControlStateNormal]

[moreButton addTarget:self action:@selector(showMoreRows)for ControlEvents:UIControlEventTouchUpInside]

//将按钮添加到表页脚视图

self.tableView.tableFooterView=moreButton

在方法上

-(iAction)showMoreRows{

//在数组中添加对象,该对象负责创建表视图,然后调用

[self.tableView重载数据]


}

这段代码对您有用吗?如果您的数据源是
photos
,那么您似乎正在尝试删除一个大于源中项目数的indexath行中的行(
[photos count]+1
应该是
[photos count]
)。如果按钮始终是表中的最后一项,则将其放在表的页脚视图中可能更容易。这样,它将始终位于底部。此代码对您有用吗?如果
photos
是您的数据源,则您似乎正在尝试删除大于NUB的indexPath行中的行源代码中项目的er(
[photos count]+1
应该是
[photos count]
)。如果按钮始终是表中的最后一个内容,则可能更容易将其放在表的页脚视图中。这样,它将始终位于底部。顺便问一下,我如何设置页脚视图的高度?您可以通过以下方式设置按钮的边框jb,我如何设置页脚视图的高度?您可以设置按钮的边框jhower,af我按下按钮后,它会添加更多行,但按钮不会再次显示。我按下按钮后,它会添加更多行,但按钮不会再次显示