0

I have created a subclass of a UITableViewCell that I am using with some UILabel's. Now I want to add a checkbox or button to this subclass. After the user clicks this button, I want to move perform a segue and pass an ID or tag.

Currently, this is what I have in the subclass. activityComplete is the button click action

- (IBAction)activityComplete:(id)sender {
     NSLog(@"row: %d", activityComplete.tag);
}

In my main class, I am calling this at cellForRowAtIndexPath:

cell.activityComplete.tag = [activityId intValue];

This is currently working and it passes the ID as the tag when I click the button. The problem is, at this point I don't know how to perform a segue. I need to call the segue from my main class but the action is happening on my subclass.

Any help would be appreciated.

Keith
  • 1,352
  • 3
  • 21
  • 48

1 Answers1

1

If you already have a segue to the scene you wish to transition to, even if it is connected to a view other than your button, ensure that you have given the segue an Identifier in the storyboard. Then you can call the performSegueWithIdentifier:sender: method using the identifier you gave to the segue and using the button as the sender.

This will call the scene as if you had hooked up the segue directly.

Rob
  • 4,149
  • 5
  • 34
  • 48
  • I tried calling [self performSegueWithIdentifier:@"activityCompleteSegue" sender:self]; From my class and I get an error "No visible @interface" for 'ActivityCell' declares the selector 'performSegueWithIdentifier:sender' – Keith May 30 '12 at 18:20
  • You will need to ensure the button's call goes back to the UITableViewController and not the UITableViewCell. The performSeguesWithIdentifier only exists in UIViewController and it's children. – Rob May 30 '12 at 21:40
  • I think that's the main problem I'm having. I'm not sure how to do that. – Keith May 31 '12 at 13:13
  • If you are using static cells (cells configured before runtime) then it's simple. You can map the touch event to the File Owner. Then when touched the action will run the code that I spoke of earlier. If you are using prototype cells (configured and loaded at runtime) then the problem is more involved. You will probably need to subclass UITableViewCell and assign it as your cell and use notification. – Rob May 31 '12 at 16:44
  • Can you explain what you mean by use notification? – Keith Jun 01 '12 at 15:33
  • Check these out. It will help. http://stackoverflow.com/questions/1900352/what-is-nsnotification https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Notifications/Introduction/introNotifications.html#//apple_ref/doc/uid/10000043i – Rob Jun 02 '12 at 13:01
  • Thanks for the help. I finally got it to pass my ID to the correct view controller and I learned something new along the way. – Keith Jun 04 '12 at 19:35