gpt4 book ai didi

ios - UITableViewCell自定义编辑内容

转载 作者:行者123 更新时间:2023-12-01 22:56:58 25 4
gpt4 key购买 nike

我希望我的单元格在编辑时不仅有“删除”按钮,而且还有其他按钮。那么实际的方法是什么呢?我尝试为 editingAccessoryView 属性创建自己的 UIView 对象,但问题是该 View 仅在直接编辑时出现(即单击导航栏中的“编辑”按钮)并完全忽略扫过单元格。另外 tableView:editActionsForRowAtIndexPath: 方法也被尝试过但没有成功,至少我没有设法弄清楚如何通过其功能获得我想要的东西。预先感谢您!

最佳答案

你试试这个代码

-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *button = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Button 1" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
NSLog(@"Action to perform with Button 1");
}];
button.backgroundColor = [UIColor greenColor]; //arbitrary color
UITableViewRowAction *button2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Button 2" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
NSLog(@"Action to perform with Button2!");
}];
button2.backgroundColor = [UIColor blueColor]; //arbitrary color

return @[button, button2]; //array with all the buttons you want. 1,2,3, etc...
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
// you need to implement this method too or nothing will work:

}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES; //tableview must be editable or nothing will work...
}

关于ios - UITableViewCell自定义编辑内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26299491/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com