Search code examples
iosobjective-cuitableviewuibuttonuiactionsheet

how to give two actions for one button in uitableview?


I've been looking around to find a solution to this, but can't seem to find one that works for me. How to do two actions for one UIButton in iOS Objective C.

My app contain "login user" and "guest user".

  • If login user comes in UITableView enquiry button navigate to one controller.
  • If "guest user" comes in UITableView enquiry button navigate to another controller

Solution

  • You can try like this

    - (IBAction)navigateToEnquire:(id)sender {
    
        NSLog(@"Button pressed: %@", [sender currentTitle]);    
    
       if ([[sender currentTitle] isEqualToString: @"login user"]) {
    
            // do something
    
       } else if ([[sender currentTitle] isEqualToString: @"guest user"]) {
    
         // do something
    
       }
    
    }