开发者

AlertView to Pause Code

This seems to be a white elephant for the iPhone. I've tried all sorts, even loops and I can't make it work.

I have a view that loads a table. However I've moved into object archiving and for development purposes I want to have an initial AlertView that asks if a user wants to use a saved database or download a fresh copy

(void)showDBAlert {

    UIActionSheet *alertDialogOpen;
    alertDialogOpen = [[UIActionSheet alloc] initWithTitle:@"DownloadDB?" 
                    delegate:self
                    cancelButtonTitle:@"Use Saved" 
                    destructiveButtonTitle:@"Download DB" 
                                         otherButtonTitles:nil];
    [alertDialogOpen showInView:self.view];
}

I'm using an ActionSheet in this instance. And I have implemented the protocol:

@interface ClubTableViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource, UIActionSheetDelegate>

Based on this I run this to check what button was pressed:

(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];
        }



    }
}

The problem is my code to build the table executes before the user has made there choice. This causes all sorts of havok. As a result, how开发者_如何学Go can I pause the code until a user has made there choice?


If you are using UITableView, you will not be able to "pause" the code, however this wouldn't be the method of choice anyways. A possible solution would be to load an empty table (return 0 in (UITableView *)tableView:numberOfRowsInSection) until the user has selected something, then reload the tableView's data with [tableView reloadData];


In your tableView:numberOfRowsInSection: just return zero until the user has made a decision.


Add [self.tableView reloadData]; at the end of the actionSheet delegate method. This will trigger all UITableViewDataSource methods again.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜