문제

I'm trying to send a segmented control variable to another file but I cant get it, I think I'm quiet close, but I need a little help, what's wrong?

--<AdSettingsTVC.m>--

@interface AdSettingsTVC () <UITextFieldDelegate, UIPickerViewDelegate, UIPickerViewDataSource>

// General Settings
@property (weak, nonatomic) IBOutlet UISegmentedControl *serverControl;
@property (weak, nonatomic) NSString *server;

@implementation AdSettingsTVC

- (IBAction)getServer:(UISegmentedControl *)sender{
    ANLogDebug(@"%@ setServidor | Server changed to Settings: %ld", CLASS_NAME, (long)sender.selectedSegmentIndex);
    if (sender.selectedSegmentIndex == 0){
        self.server = @"Server 1";
    } else if (sender.selectedSegmentIndex == 1){
        self.server = @"Server 2";
    } else if (sender.selectedSegmentIndex == 2){
        self.server = @"Server 3";
    }   
}

--<Another file.m>--

- (void)requestAdWithURL:(NSURL *)URL {

    AdSettingsTVC *settings = [[AdSettingsTVC alloc] init];

        NSString *nameServer = settings.server  --> doesn't connect
        self.URL = URL ? URL : [self adURLWithBaseURLString:[NSString stringWithFormat:@"http://%@", nameServer]];

}

Thank you very much

PD: Excuse me for my ignorance, I'm a begginer

도움이 되었습니까?

해결책

Seems like the server property of AdSettingsTVC is private because you have defined it in your .m file in a category AdSettingsTVC(). Therefore, any other file cannot access it.

Try exposing it in your .h file as

@interface AdSettingsTVC:UIViewController

@property (strong, nonatomic) NSString *server;

Also, notice the strong property

다른 팁

If you want your server variable to be accessed publicly (accessed by other objects), you must declare the property in the .h file.

So in this case you should move

@property (weak, nonatomic) NSString *server;

into AdSettingsTVC.h.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top