ObjectiveC - 按钮无法推送到VC

时间:2018-04-19 09:52:10

标签: ios uiviewcontroller uibutton uistoryboardsegue

我有一个3 buttons的VC。我完成了映射1st button以推送到VC1。当我尝试将2nd button映射到VC2时,我的程序崩溃了。为了调试,我创建了一个简单的按钮来推送到一个空的VC。它也崩溃了。我不知道发生了什么事。 3rd button没有推送到ny VC

我的故事板

Pic

我的代码

@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:

1 个答案:

答案 0 :(得分:1)

你的问题在这里

target.dataFromProfile = profileData;

作为目的地之一

ProfileEdit *target = segue.destinationViewController;

不包含变量

dataFromProfile