How to Add more button to UITableViewCell When scr

2019-04-15 14:45发布

When we are scrolling(slide to the left) UITableViewCell,it displays a delete button,but I want to add other button on it,how should I do?

The style I want is like the system mail app in iOS 7, there is two buttons in UITableviewCell,one is delete button, another is more button.

Please suggest any ideas

Thanks

5条回答
走好不送
2楼-- · 2019-04-15 15:08

A possibility, follow these steps:

1) Delegate function canEditRowAtIndexPath should return NO;

2) Load Custom cells in UITableView using cellForRowAtIndexPath.

3) In custom cells, display two or more button and handle there visibility using:

[btn setHidden:NO];

Hope it can give you an idea, how to start.

查看更多
趁早两清
3楼-- · 2019-04-15 15:10

As described at here you can achieve the same layout for cells as in Mail.app using additional UITableView datasource/delegate methods

- (NSString *)tableView:(UITableView *)tableView titleForSwipeAccessoryButtonForRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView swipeAccessoryButtonPushedForRowAtIndexPath:(NSIndexPath *)indexPath;
查看更多
地球回转人心会变
4楼-- · 2019-04-15 15:13

This is really easy, don't reinvent the wheel use this control (custom UITableViewCell) it's open source and works really well.

If you don't just want to drop it in and use it, well at least you can read exactly how they've done it! https://www.cocoacontrols.com/controls/swtableviewcell

查看更多
【Aperson】
5楼-- · 2019-04-15 15:20

you can create more button use this example approach

https://github.com/scheinem/MSCMoreOptionTableViewCell

enter image description here

this link example is helpful more and you can create customize more button.

https://github.com/CEWendel/SWTableViewCell

enter image description here

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *cellIdentifier = @"Cell"; 

    SWTableViewCell *cell = (SWTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    if (cell == nil) { 
        NSMutableArray *leftUtilityButtons = [NSMutableArray new]; 
        NSMutableArray *rightUtilityButtons = [NSMutableArray new]; 

        [leftUtilityButtons addUtilityButtonWithColor: 
                        [UIColor colorWithRed:0.07 green:0.75f blue:0.16f alpha:1.0]  
                        icon:[UIImage imageNamed:@"check.png"]]; 
        [leftUtilityButtons addUtilityButtonWithColor: 
                        [UIColor colorWithRed:1.0f green:1.0f blue:0.35f alpha:1.0]  
                        icon:[UIImage imageNamed:@"clock.png"]]; 
        [leftUtilityButtons addUtilityButtonWithColor: 
                        [UIColor colorWithRed:1.0f green:0.231f blue:0.188f alpha:1.0]  
                        icon:[UIImage imageNamed:@"cross.png"]]; 
        [leftUtilityButtons addUtilityButtonWithColor: 
                        [UIColor colorWithRed:0.55f green:0.27f blue:0.07f alpha:1.0]  
                        icon:[UIImage imageNamed:@"list.png"]]; 

        [rightUtilityButtons addUtilityButtonWithColor: 
                        [UIColor colorWithRed:0.78f green:0.78f blue:0.8f alpha:1.0] 
                        title:@"More"]; 
        [rightUtilityButtons addUtilityButtonWithColor: 
                        [UIColor colorWithRed:1.0f green:0.231f blue:0.188 alpha:1.0f]  
                            title:@"Delete"]; 

        cell = [[SWTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle  
                        reuseIdentifier:cellIdentifier  
                        containingTableView:_tableView // For row height and selection 
                        leftUtilityButtons:leftUtilityButtons  
                        rightUtilityButtons:rightUtilityButtons]; 
        cell.delegate = self; 
    } 

    NSDate *dateObject = _testArray[indexPath.row]; 
    cell.textLabel.text = [dateObject description]; 
    cell.detailTextLabel.text = @"Some detail text"; 

    return cell; 
} 
查看更多
SAY GOODBYE
6楼-- · 2019-04-15 15:20

Apple has added their own support for this

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewRowAction *editAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Edit" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {

    }];
    editAction.backgroundColor = [UIColor blueColor];

    UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Delete" handler^(UITableViewRowAction *action, NSIndexPath *indexPath) {

    }];

    return @[deleteAction, editAction];
}
查看更多
登录 后发表回答