0

I want to change DELETE button in UITableViewCell. Actually, I need to :

  1. Change position of button
  2. font
  3. text color of that button.

Here I can only change button text in following delegate method :

- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath  
{  
    UITableViewRowAction *viewAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Follow" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {  

        NSLog(@"View Action fired");  
    }];  
    viewAction.backgroundColor = [UIColor clearColor];  

    return @[callAction];  
}  

But how to change other attributes of button. If anyone knows, please let me know.

Thanks.

VRAwesome
  • 4,721
  • 5
  • 27
  • 52

2 Answers2

0

To get this working, implement the following two methods on your UITableView's delegate to get the desired effect

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

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

}

check your method you created the name of UITableViewRowAction *viewAction but you returned teh value of callAction modify once and try

- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath  
{  
    UITableViewRowAction *callAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Follow" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {  

        NSLog(@"View Action fired");  
    }];  
    callAction.backgroundColor = [UIColor clearColor];  

    return @[callAction];  
}  

In Standard UITableViewRowAction we can't change , we can change only

style

title

backgroundColor

backgroundEffect

for more information see the Apple Documents

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
  • I know about which methods I have to implement to get this working...I think you didn't understand my question... :( – VRAwesome Aug 29 '16 at 10:57
  • I need solution for changing button properties, not for how to work and what should be implemented..... Anyway thanks for reply... :) – VRAwesome Aug 29 '16 at 11:04
  • 1
    @VRAwesome - no We Can't, may be alternate way see this http://stackoverflow.com/questions/19164188/custom-edit-view-in-uitableviewcell-while-swipe-left-objective-c-or-swift – Anbu.Karthik Aug 29 '16 at 11:05
  • Thanks... @Anbu.Karthik – VRAwesome Aug 29 '16 at 11:16
  • @VRAwesome - if you are interested in third party then go by payal answer, may be it solve your issue – Anbu.Karthik Aug 29 '16 at 11:18
-1

You can create a custom cell and add custom UIButton into cell. I have a example

enter image description here

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    ViewOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath] ;

    if (cell == nil)
    {
        cell = [[ViewOrderCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }

    [cell.btnUpdate addTarget:self action:@selector(updateOrder:) forControlEvents:UIControlEventTouchUpInside];
    [cell.btnDelete addTarget:self action:@selector(deleteOrder:) forControlEvents:UIControlEventTouchUpInside];

    return cell;
}

-(void)updateOrder:(id)sender
{
    NSLog(@"update");
}
-(void)deleteOrder:(id)sender
{
    NSLog(@"delete");
}

Hope this helps.

Kamlesh Shingarakhiya
  • 2,757
  • 2
  • 16
  • 34