2012-04-30 28 views
0

目前,我有一個UITableView和2行。如圖所示。它由一個數組在ViewDidLoad中設置。禁用UITableViewController的第二行

enter image description here

viewDidLoad中

- (void)viewDidLoad { 

[super viewDidLoad]; 
self.title = NSLocalizedString(@"Analysis", @"Badminton Analysis Tool"); 
NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:@"Statistical Analysis", @"Graphical Analysis", nil]; 
self.booksArray = array; 
} 

didSelectRowAtIndexPath方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {  
NSInteger row = [indexPath row]; 

if (self.statViewController == nil) { 
    StatViewController *statDetail = [[StatViewController alloc] initWithNibName:@"StatViewController" bundle:nil]; 
    self.statViewController = statDetail; 
} 
statViewController.title = [NSString stringWithFormat:@"%@", [booksArray objectAtIndex:row]]; 

[self.navigationController pushViewController:statViewController animated:YES]; 
} 

此刻,當我點擊任一列,它推到我只打算了同樣的觀點爲'統計分析'。我想禁用點擊進行圖形分析。我如何禁用'圖形分析'的選擇?

謝謝。

回答

2

從您的表格視圖中返回nil代表的方法-tableView:willSelectRowAtIndexPath方法。

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (indexPath.row == 1) 
     return nil; 
    else 
     return indexPath; 
} 
+0

嗨,我該如何在上面的代碼中實現?謝謝。 –

+0

你必須將它添加到你的UITableView的委託類中。 – 2012-04-30 14:36:12

+0

不錯,它的作品。謝謝。但是當我點擊第二排時,它有時會閃爍。當我嘗試點擊第二行時,如何禁用藍色閃光燈? –

1

實現tableView:willSelectRowAtIndexPath :(見文檔)並返回nil,如果路徑匹配你想要禁用的。

+0

嘿菲利普,關於我上面的代碼。我怎樣才能實現它? –

1

可以通過使用這個索引取消選擇行: - [self.tableView deselectRowAtIndexPath:indexPath動畫:YES];

投票給我答案,並通過投票箭頭增加我的聲望。

+0

如何在deselectRowAtIndexPath的索引處取消選擇行?謝謝。 –

1
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
     if(indexPath.row == 1) { 
     [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
     return; 
     } 
} 
+0

不錯,它的作品。謝謝。但是當我點擊第二排時,它有時會閃爍。當我嘗試點擊第二行時,如何禁用藍色閃光燈? –

1

對於去功能的藍色閃光,做這樣的事情:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    if (cell == nil)  { 
    //usually this is the place where we decide the selection style blue/none 

}
如果(indexPath.row == 1){
cell.setUserInteractionEnabled = NO; //這種方式didSelectrow委託方法將不會被調用。
else {
cell.setUserInteractionEnabled = YES;
}
return cell;
}
希望它能幫助你。

0

編譯標記 -

編譯標記表視圖代表

  • (無效)的tableView:(UITableView的*)的tableView didSelectRowAtIndexPath方法:(NSIndexPath *)indexPath {

    如果(indexPath.row == 0) {

    iHadAppDelegate *delegate = [[UIApplication sharedApplication] delegate]; 
    delegate.flag = 0; 
    delegate.mytag = 0; 
    
    TableSelectMealViewController *detail = 
    [[TableSelectMealViewController alloc] initWithStyle:UITableViewStyleGrouped]; 
    detail.rows = 6; 
    [self.navigationController pushViewController:detail animated:YES]; 
    SelectMealViewController.contentSizeForViewInPopover = CGSizeMake(285, 400); 
    
    [detail release]; 
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    

    }

    if(indexPath.row == 1) { iHadAppDelegate * delegate = [[UIApplication sharedApplication] delegate]; 代表。flag = 1;

    DatePickerViewController *controller = [[DatePickerViewController alloc]init]; 
    [self.navigationController pushViewController:controller animated:YES]; 
    controller.contentSizeForViewInPopover = CGSizeMake(285, 400); 
    
    [controller release]; 
    

    }

    如果(indexPath.row == 2){ iHadAppDelegate *代表= [[UIApplication的sharedApplication]委託]; delegate.flag = 2;

    }

    如果(indexPath.row == 3){ iHadAppDelegate *代表= [[UIApplication的sharedApplication]委託]; delegate.flag = 3;

    TableSelectMealViewController *detail = 
    [[TableSelectMealViewController alloc] initWithStyle:UITableViewStyleGrouped]; 
    //detail.rows = 10; 
    [self.navigationController pushViewController:detail animated:YES]; 
    
    SelectMealViewController.contentSizeForViewInPopover = CGSizeMake(285, 400); 
    
    [detail release]; 
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    

    }

}

@ k.Honda從我的代碼的意見。

[self.tableView deselectRowAtIndexPath:indexPath animated:YES]; 

使用了 - 在這裏我要取消選擇的行[不是每行向僅在該行,我想取消。

相關問題