UPDATED - have an app that displays a list of files for the user to select from; the list of files is in a UITableView which is in a UIPopover. This is the code that displays a UIPopover of the contents of a list of files; the user is expected to pick one of the files at which point processing will continue. Right now, processing continues without the user picking a file from the list, which makes no sense (can't process a file unless I know which file to process!):
-(void)browseDirectory {
CommonMethods *cm = [[CommonMethods alloc]init];
fileList = [cm listContentsOfDirectory];
// format popover to display fileList
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 340, 400)];
popoverView.backgroundColor = UIColorFromRGB(0xFFF9AF);
popoverContent.view = popoverView;
//resize the popover view shown in the current view to the view's size
popoverContent.preferredContentSize = CGSizeMake(340, 400);
// create a UITableView to display the contents of the array
UITableView *tableView = [[UITableView alloc] initWithFrame:popoverView.frame style:UITableViewStylePlain];
// must set delegate & dataSource, otherwise the the table will be empty and not responsive
tableView.delegate = self;
tableView.dataSource = self;
// add to canvas
[popoverView addSubview:tableView];
// if previous popoverController is still visible... dismiss it
if ([popoverController isPopoverVisible])
[popoverController dismissPopoverAnimated:YES];
//create a popover controller
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[popoverController presentPopoverFromRect:((UIButton *)oUpload).frame inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
// number of section(s), now I assume there is only 1 section
- (NSInteger)numberOfSectionsInTableView:(UITableView *)theTableView {
return 1;
}
// number of row in the section, I assume there is only 1 row
- (NSInteger)tableView:(UITableView *)theTableView numberOfRowsInSection:(NSInteger)section {
return fileList.count;
}
// the cell will be returned to the tableView
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"FilenameCell";
UITableViewCell *cell = (UITableViewCell *)[theTableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = fileList[indexPath.row];
return cell;
}
This is the code where -browseDirectory is called:
[self browseDirectory]; // drops through!
if(cbvABE.checked == YES) { // tab-delimited
[self createTabExportFile: @"ABE"]; {
cbvEmailABE.checked? [self sendViaEmail:@"ABE"]:[self uploadToABE];
}
}
The question is: how do I prevent (or block) the execution from continuing after I call -browseDirectory until the user has selected a row in the UITableView?
You need to move your processing code to
tableView:didSelectRowAtIndexPath:
This will be called by the table view when a user selects a cell. You can get the selected file using the row
property of the indexPath
as index of the file array.