目前,我有一个UITableView
并且有两行。如图所示。它由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];
}
目前,当我点击任意一行时,它会推送到我打算仅用于“统计分析”的相同视图。我想禁用点击图形分析。如何禁用“图形分析”的选择?
感谢。
答案 0 :(得分:2)
从表格视图委托的nil
方法返回-tableView:willSelectRowAtIndexPath
。
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 1)
return nil;
else
return indexPath;
}
答案 1 :(得分:1)
实现tableView:willSelectRowAtIndexPath :(参见文档),如果路径与您想要禁用的内容相匹配,则返回nil。
答案 2 :(得分:1)
您可以使用以下方法取消选择索引处的行: - [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
投票给我答案并通过投票箭头来提高我的声誉。
答案 3 :(得分:1)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == 1) {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
return;
}
}
答案 4 :(得分: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;
}
返回单元;
}
希望它会对你有所帮助。
答案 5 :(得分: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]; delegate.flag = 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]; delegate.flag = 2;
}
if(indexPath.row == 3) { iHadAppDelegate * delegate = [[UIApplication sharedApplication] delegate]; 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];
用于 - 我想取消选择行[不是每一行 - 只有我要取消选择的行]。