1

这是一个奇怪的问题。我正在使用 NSURLConnectionDelegate 从 Web 服务中检索信息。在 connectionDidFinishLoading 方法中,我向委托发送消息以更新 UITableView 并隐藏“正在加载...”UILabel。委托方法被调用,更新表格视图和隐藏标签的代码被调用,但标签和表格视图没有响应。我在 IB 中正确连接了所有内容,因为我能够在关闭/重新打开视图时隐藏/显示标签并更新表格视图。任何帮助将不胜感激。

相关代码:

// File with NSURLConnection
// .h
@protocol updateTableViewDelegate <NSObject>
-(void)didFinishLoadingData;
@end

@property (nonatomic, assign) id <updateTableViewDelegate> delegate;

// .m
@synthesize delegate;

- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
       if (delegate && [delegate respondsToSelector:@selector(didFinishLoadingData)]) {
        [delegate didFinishLoadingData];
       }    
}

// connection started with
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];


// File with table view

// conform to <updateTableViewDelegate> in header file
// set the delegate of NSURLConnection object to self in viewDidLoad

-(void)didFinishLoadingData{

    self.viewLoading.hidden = YES;

    // Repopulate array of data for table view
    ....

    [self.tblViewLookup reloadData];
}
4

1 回答 1

0

使用 dispatch_async(dispatch_get_main_queue(), ^{ //你的代码更新 UI }

于 2013-08-28T22:21:07.063 回答