【发布时间】:2012-12-03 13:27:58
【问题描述】:
我正在 Xcode 4.2 上开发 iOS 5.1 应用程序。 我有一个带有不同选项卡的 uitablcontroller。我的问题是,当单击一个选项卡时,应用程序会“冻结”几秒钟并执行它应该执行的所有代码,但它没有按应有的方式首先加载 UIAlertView。
我在 viewDidLoad 中声明了 UIAlertView。 这是一个代码sn-p:
- (void)viewDidLoad
{
NSLog(@"##### VIEW DID LOAD 1 #####");
// Display Alert: Loading
alertView = [[UIAlertView alloc] initWithTitle:@"Loading"
message:@"\n"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.center = CGPointMake(139.5, 75.5); // .5 so it doesn't blur
[alertView addSubview:spinner];
[spinner startAnimating];
[alertView show];
[super viewDidLoad];
NSLog(@"##### VIEW DID LOAD 2 #####");
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self callMainMethod];
}
点击tab的时候,可以看到Log中显示了第一个NSLog,然后调用了main方法,但是没有显示UIAlertview。
【问题讨论】:
-
勘误,我使用的是 Xcode 4.5
-
在自定义实现之前尝试调用superview的
viewDidLoad。 -
##解决方案## emrys57的回答解决了问题!答案是将[self callMainMethod]移到viewDidAppear。我还需要在调用函数后放置 [self.tableview reloadData],因为我需要查看 Table 上的数据。
标签: objective-c ios uialertview freeze uitabcontroller