0

目前,我有一个UITableView和 2 行。如图所示。它由 中的数组设置ViewDidLoad

在此处输入图像描述

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

目前,当我单击任一行时,它会推送到我只打算用于“统计分析”的同一视图。我想禁用点击图形分析。如何禁用“图形分析”的选择?

谢谢。

4

6 回答 6

2

nil从您的表视图委托的-tableView:willSelectRowAtIndexPath方法返回。

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 1)
        return nil;
    else
        return indexPath;
}
于 2012-04-30T14:19:42.137 回答
1

实现 tableView:willSelectRowAtIndexPath: (请参阅文档)并在路径与您想要禁用的路径匹配时返回 nil。

于 2012-04-30T14:19:30.880 回答
1

您可以使用以下方法取消选择索引处的行:- [self.tableView deselectRowAtIndexPath:indexPath animated:YES];

投票我的答案并通过向上投票箭头来提高我的声誉。

于 2012-04-30T14:24:44.117 回答
1
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {  
      if(indexPath.row == 1) {
         [tableView deselectRowAtIndexPath:indexPath animated:YES];
         return;
       }
}
于 2012-04-30T15:42:34.037 回答
1

要禁用蓝色闪光,请执行以下操作:

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

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

}
if(indexPath.row == 1) {
cell.setUserInteractionEnabled = NO;//这样不会调用didSelectrow委托方法。
否则 {
cell.setUserInteractionEnabled = YES;
}
返回单元格;
}
希望它会帮助你。

于 2012-04-30T16:23:10.883 回答
0

语用标记 -

杂注标记表视图委托

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

    if (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]; 委托标志 = 1;

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

    }

    if (indexPath.row == 2) { iHadAppDelegate *delegate = [[UIApplication sharedApplication] delegate]; 委托标志 = 2;

    }

    if (indexPath.row == 3) { iHadAppDelegate *delegate = [[UIApplication sharedApplication] delegate]; 委托标志 = 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];

用于——我想取消选择行的地方[不是每一行——只有我想取消选择的那一行]。

于 2012-05-01T05:14:03.393 回答