Unrecognized selector sent to instance using Storyboards

前端 未结 3 1432
既然无缘
既然无缘 2020-12-25 14:43

I\'m using storyboard for an iOS application, my storyboard looks like this: http://d.pr/7yAY (droplr url)

The problem is when I click the login button, I send the u

相关标签:
3条回答
  • 2020-12-25 15:18

    Your segue's destination view controller is your Navigation Controller, not your Events Table View controller.

    You can get the Events controller by accessing the Navigation controller's topViewController property.

    Try this:

    UINavigationController *navController = (UINavigationController*)[segue destinationViewController];
    EventsTableViewController *eventsController = [navController topViewController];
    
    NSString * username = [[NSString alloc] initWithFormat:@"%@", username_tf.text];
    [eventsController setUsername:username];
    
    0 讨论(0)
  • 2020-12-25 15:36

    Another thing to verify is that you have properly assigned your destination ViewController as the proper class in Interface Builder. By default this will be UIViewController or UITableViewController etc. If you have a custom class with getters/setters, you need to remember to change the class in the Interface Builder to reflect accordingly, otherwise you will receive an invalid selector error message.

    0 讨论(0)
  • 2020-12-25 15:37

    Alternatively, try this:-

    (It does the same as jonkroll's answer but in one line and removes the warning "Incompatible pointer types initializing 'ViewController *__strong' with an expression of type UIViewController *"

     NameOfViewController *vc = (NameOfViewController *)[[segue destinationViewController] topViewController];
    
    0 讨论(0)
提交回复
热议问题