2014-10-03 59 views
1

已更新 -有一个应用程序,显示供用户选择的文件列表;文件列表位于UIPopover中的UITableView中。这是显示文件列表内容的UIPopover的代码;预计用户将选择其中一个文件,在该文件处处理将继续。眼下,处理继续没有用户选择从列表中,这是没有意义的文件(无法处理文件,除非我知道要处理的文件!):如何阻止执行,直到用户选择在UIPopover中的UITableView中的行?

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

这是代码,其中-browseDirectory被称为:

[self browseDirectory]; // drops through! 

if(cbvABE.checked == YES) { // tab-delimited 
    [self createTabExportFile: @"ABE"]; { 
     cbvEmailABE.checked? [self sendViaEmail:@"ABE"]:[self uploadToABE]; 
    } 
} 

的问题是:我该如何防止(或块)的持续后,我打电话-browseDirectory直到用户在选定的UITableView行执行?

+0

我不明白你需要什么。你有一些代码,你需要解释它的作用 - 没有人想读一段代码而没有解释 - 而你想要的东西,但你没有描述你想要什么,什么出了问题。请更新您的问题以获取更多信息 – 2014-10-05 19:22:56

+0

澄清问题;请删除倒票。 – SpokaneDude 2014-10-05 20:58:12

+0

已删除。现在就回答它。 – 2014-10-05 20:59:17

回答

1

你需要当用户选择一个单元来移动你的处理代码

tableView:didSelectRowAtIndexPath: 

这将通过表视图被调用。您可以使用indexPathrow属性作为文件数组的索引来获取所选文件。

+0

令人难以置信!我想我太参与了,甚至想不到!谢谢...让我放弃一下,我会回到你身边......再次感谢。 – SpokaneDude 2014-10-05 21:16:52

+0

干杯。不用担心,有时我们会错过最明显的事情,而且我们需要第二双眼睛。快乐的编码。 – 2014-10-05 21:19:10

+1

我得等几天奖励赏金!应得的!我已经为此工作了4天,终于像冠军一样工作了!不够感谢你! SD – SpokaneDude 2014-10-05 21:27:08

相关问题