ios - AlertView 暂停代码

标签 ios objective-c iphone tableview uialertview

这似乎是 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/

相关文章:

iphone - 使用 openGL 捕获屏幕截图

ios - 如何在 iOS 的谷歌地图上使用 CLLocationManager 生成我的旅行路径?

ios - UIView animateWithDuration 重新开始

iPhone文件系统操作问题

ios - Cocos2D + 仅禁用 Retina iPad 图形

ios - 如何在ios中对NSMutableArray中的时间进行排序

objective-c - 使带有透明标题栏的 NSWindow 部分不可移动

iphone - 将 GMT 时间转换为本地时间

iOS,应用程序商店的 url 方案既适用于指定开发人员的应用程序,也适用于他在 iOS 6 中更新的具体应用程序?

ios - MPVolumeView 在启动时不显示路线按钮