2014-10-03 36 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

相關問題