3 回答

TA貢獻1780條經驗 獲得超1個贊
我只是在Objective-C中添加以下內容,以使初學者(以及我們中那些拒絕學習Swift語法的人)更加清楚:
確保聲明uitableviewdelegate并具有以下方法:
?-(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...
? ? }

TA貢獻1946條經驗 獲得超3個贊
現在可以使用以下公共API來完成此操作:
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
? ? let moreRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "More", handler:{action, indexpath in
? ? ? ? print("MORE?ACTION");
? ? });
? ? moreRowAction.backgroundColor = UIColor(red: 0.298, green: 0.851, blue: 0.3922, alpha: 1.0);
? ? let deleteRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "Delete", handler:{action, indexpath in
? ? ? ? print("DELETE?ACTION");
? ? });
? ? return [deleteRowAction, moreRowAction];
}
- 3 回答
- 0 關注
- 733 瀏覽
添加回答
舉報