Instance variable not retaining value in iOS application

后端 未结 2 1613
遇见更好的自我
遇见更好的自我 2021-01-24 07:33

I have declared this ivar in my

ViewController.h

#import 

@interface FirstViewController : UIViewController 

        
相关标签:
2条回答
  • 2021-01-24 07:51
    NSArray *sortedCountries = [[countries sortedArrayUsingDescriptors:[NSArray arrayWithObject:descriptor]]retain];
    

    to

    self.sortedCountries = [countries sortedArrayUsingDescriptors:[NSArray arrayWithObject:descriptor]];
    
    0 讨论(0)
  • 2021-01-24 07:58

    You are re-declaring sortedCountries as a local variable in viewDidLoad. Use:

    sortedCountries = ...
    

    instead (notice no NSArray *). In the code you are using now, sortedCountries would be populated in viewDidLoad, but accessible only in viewDidLoad. You were creating a new variable with the same name instead of setting the class property.

    0 讨论(0)
提交回复
热议问题