简体   繁体   English

Objective-C。 DismissVC 与委托

[英]Objective-C. DismissVC with the delegate

I have a VC, lets call it UserInfoVC , that is a subclass of UIViewController .我有一个 VC,我们称之为UserInfoVC ,它是UIViewController的子类。 That UserInfoVC holds another UIView .UserInfoVC持有另一个UIView That UIView holds a UIButton .UIView持有UIButton With the custom protocol, from that UIView with the UIButton , when the button is tapped, I would like to dismiss that UserInfoVC (vc was presented modally).使用自定义协议,从UIViewUIButton 开始,当点击按钮时,我想关闭UserInfoVC (vc 以模态方式呈现)。

So I have created that method in my UserInfoVC所以我在我的UserInfoVC中创建了该方法

-(void)dismissVC {
    [self dismissVC];
}

Next, the method is called from protocol method like this:接下来,从协议方法调用该方法,如下所示:

- (void)didTapGetFollowersForUser:(User *)user {
    if (self.user.followers == 0) {
        NSLog(@"No followers for that guy, sorry");
    } else {
        [self dismissVC];
        [self.delegate didRequestFollowersForUsername:user.login];
    }
}

I am getting that error form [self dismissVC] line: Thread 1: EXC_BAD_ACCESS (code=2, address=0x16cb87ff0)我收到错误表单[self dismissVC]行:线程 1:EXC_BAD_ACCESS (code=2, address=0x16cb87ff0)

I would like to add that I am currently learning Objective-C.我想补充一点,我目前正在学习 Objective-C。 I am trying to translate some of my previous projects and see the differences.我正在尝试翻译我以前的一些项目并查看其中的差异。 The exact same code in Swift works just fine for me. Swift 中完全相同的代码对我来说工作得很好。

Many thanks for the help.非常感谢您的帮助。

you created an infinite loop with this method:您使用此方法创建了一个无限循环:

-(void)dismissVC {
    [self dismissVC];
}

[self dismissVC] call will invoke the same method. [self dismissVC]调用将调用相同的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM