It is possible to use an existing ViewController with PerformSegueWithIdentifier?

后端 未结 7 1533
一整个雨季
一整个雨季 2020-12-31 05:32

I use the method performSegueWithIdentifier:sender: to open a new ViewController from a storyboard-file programmatically. This works like a charm.<

7条回答
  •  忘掉有多难
    2020-12-31 05:40

    Following code makes singleton view controller. Add them to your destination view controller implementation, then segue will reuse the same vc.

    static id s_singleton = nil;
    + (id) alloc {
        if(s_singleton != nil)
            return s_singleton;
        return [super alloc];
    }
    - (id) initWithCoder:(NSCoder *)aDecoder {
        if(s_singleton != nil)
            return s_singleton;
        self = [super initWithCoder:aDecoder];
        if(self) {
            s_singleton = self;
        }
        return self;
    }
    

提交回复
热议问题