Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 从回调函数更新UI_Objective C - Fatal编程技术网

Objective c 从回调函数更新UI

Objective c 从回调函数更新UI,objective-c,Objective C,我正在使用执行异步请求,我想用请求中的新信息更新Textbox,所以我正在从回调函数更新它。 以下是我目前的代码: 二等舱 AppController是一个主类。从那里设置文本是可行的。但这段代码什么都没做。它只向调试窗口写入了两行日志 我遗漏了什么吗?你能确认ac不是nil?您可以发布AppController的方法getInstance的代码吗?您能否确认ac.textbox不是nil?[AppController getInstance]做什么?您确定它返回了正确的引用吗?getInst

我正在使用执行异步请求,我想用请求中的新信息更新Textbox,所以我正在从回调函数更新它。 以下是我目前的代码:

二等舱

AppController是一个主类。从那里设置文本是可行的。但这段代码什么都没做。它只向调试窗口写入了两行日志


我遗漏了什么吗?

你能确认
ac
不是
nil
?您可以发布
AppController
的方法
getInstance
的代码吗?您能否确认
ac.textbox
不是
nil
?[AppController getInstance]做什么?您确定它返回了正确的引用吗?getInstance确保该类是singleton。ac不是零,但textbox是零。不知道为什么,因为textbox是一个属性:@property(弱)IBOutlet NSTextField*textbox;如果您从未加载AppController.xib,我认为您的文本框将为零。应加载xib以使文本框具有有效地址。
- (void)Login {
    NSLog(@"Login");
    NSURL *url = [NSURL URLWithString:@"http://ts5.travian.sk/login.php"];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setDelegate:self];
    [request setDidFinishSelector:@selector(loginRequestFinished:)];
    [request setDidFailSelector:@selector(loginRequestFailed:)];
    [request startAsynchronous];
}

- (void)loginRequestFinished:(ASIHTTPRequest *)request
{
    NSLog(@"Completed!");
    NSString *response = [request responseString];
    AppController *ac = [AppController getInstance];
    [ac.textbox performSelectorOnMainThread:@selector(setStringValue:) withObject:response waitUntilDone:NO];
}