Search code examples
iosuiviewcontrolleruibuttonuistoryboardsegue

ObjectiveC - Button can't push to a VC


I have a VC with 3 buttons. I finish mapping 1st button to push to VC1. When I try to map the 2nd button to push to VC2, my program crashed. To debug, I created a simple button to push to an empty VC. It crashed as well. I have no idea what is going on. 3rd button does not push to any VC.

MY STORYBOARD

Pic

MY CODE

@synthesize btnEditProfile;
@synthesize btnChgLang;
@synthesize btnLogOut;

- (void)viewDidLoad {
    [super viewDidLoad];

    //=== Customize the btn
    btnEditProfile.layer.cornerRadius =7.0f;
    btnEditProfile.layer.shadowRadius = 3.0f;
    btnEditProfile.layer.shadowColor = [UIColor blackColor].CGColor;
    btnEditProfile.layer.shadowOffset = CGSizeMake(0.0f, 2.0f);
    btnEditProfile.layer.shadowOpacity = 0.5f;
    btnEditProfile.layer.masksToBounds = NO;

    //=== Customize the btn
    btnChgLang.layer.cornerRadius =7.0f;
    btnChgLang.layer.shadowRadius = 3.0f;
    btnChgLang.layer.shadowColor = [UIColor blackColor].CGColor;
    btnChgLang.layer.shadowOffset = CGSizeMake(0.0f, 2.0f);
    btnChgLang.layer.shadowOpacity = 0.5f;
    btnChgLang.layer.masksToBounds = NO;

//=== Customize the btn
btnLogOut.layer.cornerRadius =7.0f;
btnLogOut.layer.shadowRadius = 3.0f;
btnLogOut.layer.shadowColor = [UIColor blackColor].CGColor;
btnLogOut.layer.shadowOffset = CGSizeMake(0.0f, 2.0f);
btnLogOut.layer.shadowOpacity = 0.5f;
btnLogOut.layer.masksToBounds = NO;
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    ProfileEdit *target = segue.destinationViewController;

    if ([segue.identifier isEqualToString:@"EditProfile"]) {

        target.dataFromProfile = profileData;

    } else {

        target.dataFromProfile = profileData;
    }
}


- (IBAction)btnEditProfile:(id)sender {

    [self performSegueWithIdentifier:@"EditProfile" sender:self]; 
}

- (IBAction)btnChgLang:(id)sender {

    NSLog(@"What is going on ? ");

    //[self performSegueWithIdentifier:@"ChangeLang" sender:self];
}


- (IBAction)btnLogOut:(id)sender {

    User *userObj = [[User alloc] init];
    [userObj logout];

    //AppDelegate *authObj = (AppDelegate*)[[UIApplication sharedApplication] delegate];
//authObj.authenticated = YES;

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

    RootViewController *initView =  (RootViewController*)[storyboard instantiateViewControllerWithIdentifier:@"RootNavigationControllerID"];
    [initView setModalPresentationStyle:UIModalPresentationFullScreen];
    [self presentViewController:initView animated:NO completion:nil];

}

ERROR

  2018-04-19 17:47:10.846656+0800 SFITNESS[53692:4752813] -[UIViewController setDataFromProfile:]: unrecognized selector sent to instance 0x7fb2f7f8e490
  2018-04-19 17:47:10.867342+0800 SFITNESS[53692:4752813] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController setDataFromProfile:]: unrecognized selector sent to instance 0x7fb2f7f8e490'
  *** First throw call stack:

Solution

  • Your problem is here

    target.dataFromProfile = profileData;
    

    as one of the destination

    ProfileEdit *target = segue.destinationViewController;
    

    doesn't contain variable

    dataFromProfile