【发布时间】:2014-02-15 16:21:48
【问题描述】:
我有一个很奇怪的问题。我正在 AFNetworking 的完成块内初始化一些 UI 元素,其中只有一个 (UIBarButtonItem) 未初始化。这是我的代码,位于viewDidLoad:
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[m_httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSError* error;
self.m_pointData = [NSJSONSerialization
JSONObjectWithData:responseObject
options:kNilOptions
error:&error];
[self InitializeFields];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"Error in get point response: %@", error);
}];
[operation start];
}
我在 InitializeFields 中进行初始化,代码如下:
self.m_placeName.text = [self.m_pointData objectForKey:@"name"];
self.m_placeLocation.text = [self.m_pointData objectForKey:@"city"];
NSArray* comments = [self.m_pointData objectForKey:@"comments"];
const int commentsCount = [comments count];
self.m_commentsCount.text = [NSString stringWithFormat:@"%d", commentsCount];
self.m_scrollView.m_address.text = [self.m_pointData objectForKey:@"address"];
self.m_scrollView.m_email.text = [self.m_pointData objectForKey:@"email"];
self.m_scrollView.m_phone.text = [self.m_pointData objectForKey:@"tel"];
self.m_scrollView.m_link.text = [self.m_pointData objectForKey:@"website"];
self.m_rightBtn.image = [UIImage imageNamed:@"favorite_star_inactive.png"];
只有最后一行 - self.m_rightBtn.image = [UIImage imageNamed:@"favorite_star_inactive.png"]; - 不起作用。当我将其移至viewDidLoad 时,它可以工作。有完成块的东西,但我不知道是什么。
【问题讨论】:
标签: ios objective-c afnetworking objective-c-blocks uibarbuttonitem