Static NSArray of strings - how/where to initialize in a View Controller

前端 未结 9 1924
甜味超标
甜味超标 2020-12-12 21:16

In a Master-Detail app I\'d like to display a TableView with 5 sections titled:

  1. Your Move
  2. Their Move
  3. Won Games
  4. Lost Games
  5. O
9条回答
  •  隐瞒了意图╮
    2020-12-12 21:50

    You should declare your static array above @implementation.

    static NSArray *titles_1 = nil;
    
    @implementation ...
    

    And define it in init or awakeFromNib or any other method like viewDidLoad, applicationDidFinishLaunching wherever you want.

    - (void)initMethod{ //change the method name accordingly
    
        if (titles_1 == nil){
            [self setTitles_1:@[ @"Your Move", @"Their Move", @"Won Games", @"Lost Games", @"Options" ]];
        }
    }
    

提交回复
热议问题