2011-10-12 50 views
0

我有一個tableView。在TableView上顯示項目 - 新手

在每個小區i顯示以下字符ABC等。

A用戶點擊我需要的頁去那個示出了另一個的tableView,打印以下文本另一視圖AmericaAustralia。 (這部分已完成)

當用戶點擊B,該視圖進入其他頁面,但由於沒有國家的字符B說明它顯示了一個 空表。

當用戶點擊C國家CanadaChina得到顯示。

我想要做的是,當用戶點擊B,因爲沒有任何國家,我不希望頁面被重定向到另一個顯示空表的頁面。

我該如何解決這個問題?

** * *所有國家名稱從源碼

裝我加入如下代碼,所以這就是爲什麼我所有的屏幕獲得定向到其他視圖(和B顯示一個空tableView)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 


    Countries *viewControllerCountries = [[Countries alloc] initWithNibName:@"Countries" bundle:nil]; 

    [self.navigationController pushViewController:viewControllerCountries animated:YES]; 

    [viewController release]; 

} 
+0

Illep,具有u解決你的問題 ? – Prajan

+0

不,我沒有。如果你有解決方案,請讓我知道 – Illep

回答

0

在您的Countries類中創建一個方法來允許您的父視圖控制器檢索記錄計數。如果計數爲0,則不要推視圖。

P.S.我認爲像CountriesViewController這樣的東西比國家更容易混淆。

0
- (void)viewDidLoad 

    Array=[[NSMutableArray alloc]init]; 
    [Array1 addObject:@"A",@"B",@"C",nil]; 

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
Static NSString *[email protected]"cell"; 
    cell=[tbView dequeueReusableCellWithIdentifier:cellIdentifier]; 
    if(cell==nil) 
    { 
     cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
    } 

    if(tableView==self.tbView) 
    { 
     cell.textLabel.text=[Array objectAtIndex:indexPath.row]; 
    } 
    cell.textLabel.font=[UIFont boldSystemFontOfSize:14]; 
    return cell; 
} 
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
if(tableView==self.tbView) 
    { 
     return [Array count]; 
    } 
//when select the tableview cell want you want set codes here 
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

    { 
} 
+0

'當用戶點擊B並且因爲沒有任何國家,我不希望頁面被重定向到另一個顯示空表的頁面。「< - 但它並沒有解釋這一點 – Illep

0

- (空)的tableView:(UITableView的*)的tableView didSelectRowAtIndexPath方法:(NSIndexPath *)indexPath

{ 

//代碼在這裏 }