Colin Colin - 1 year ago 84
iOS Question

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?"
cancelButtonTitle:@"Use Saved"
destructiveButtonTitle:@"Download DB"
[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 can I pause the code until a user has made there choice?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download