这似乎是 iPhone 的白象。我已经尝试了各种方法,甚至是循环,但我无法让它工作。
我有一个加载表格的 View 。然而,我已经进入对象归档,出于开发目的,我想要一个初始的 AlertView,询问用户是否想使用已保存的数据库或下载新副本
(void)showDBAlert {
UIActionSheet *alertDialogOpen;
alertDialogOpen = [[UIActionSheet alloc] initWithTitle:@"DownloadDB?"
delegate:self
cancelButtonTitle:@"Use Saved"
destructiveButtonTitle:@"Download DB"
otherButtonTitles:nil];
[alertDialogOpen showInView:self.view];
}
我在这个实例中使用了一个 ActionSheet。我已经实现了协议(protocol):
@interface ClubTableViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource, UIActionSheetDelegate>
基于此,我运行它来检查按下了哪个按钮:
(void)actionSheet:(UIActionSheet *) actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *buttonTitle=[actionSheet buttonTitleAtIndex:buttonIndex];
if ( [buttonTitle isEqualToString:@"Download DB"] ) {
[self loadDataFromDB];
}
if ([buttonTitle isEqualToString:@"Use Saved"] ) {
self.rows = [NSKeyedUnarchiver unarchiveObjectWithFile:[self archivePath]];
if (self.rows == nil) {
[self loadDataFromDB];
}
}
}
问题是我的建表代码是在用户做出选择之前执行的。这会导致各种破坏。因此,我如何暂停代码直到用户做出选择?
最佳答案
如果您使用的是 UITableView,您将无法“暂停”代码,但这无论如何都不是选择的方法。一个可能的解决方案是加载一个空表(return 0
in (UITableView *)tableView:numberOfRowsInSection)
直到用户选择了一些东西,然后使用 重新加载 tableView 的数据code>[tableView reloadData];
关于ios - AlertView 暂停代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4184482/