【问题标题】:ObjectiveC - Button can't push to a VC目标 C - 按钮无法推送到 VC
【发布时间】:2018-09-29 18:37:08
【问题描述】:

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

我的故事板

我的代码

@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];

}

错误

  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:

【问题讨论】:

  • 您应该将该视图控制器的类设置为 ProfileEdit

标签: ios uiviewcontroller uibutton uistoryboardsegue


【解决方案1】:

你的问题来了

target.dataFromProfile = profileData;

作为目的地之一

ProfileEdit *target = segue.destinationViewController;

不包含变量

dataFromProfile

【讨论】:

    猜你喜欢
    • 2020-12-02
    • 1970-01-01
    • 2020-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多