Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 是否有类似于表视图中的did select section的方法_Iphone_Tableview - Fatal编程技术网

Iphone 是否有类似于表视图中的did select section的方法

Iphone 是否有类似于表视图中的did select section的方法,iphone,tableview,Iphone,Tableview,我想在一个单独的视图中显示该节的数据,如果用户触摸到该节。。 有人能告诉我怎么做吗?使用并测试indexPath.section属性,例如: switch (indexPath.section) case kFirstSection: [self doSomethingWithCustomViewForSection:kFirstSection]; break; case kSecondSection: [self doSomet

我想在一个单独的视图中显示该节的数据,如果用户触摸到该节。。 有人能告诉我怎么做吗?

使用并测试
indexPath.section
属性,例如:

switch (indexPath.section) 
    case kFirstSection:
        [self doSomethingWithCustomViewForSection:kFirstSection];
        break;
    case kSecondSection:
        [self doSomethingWithCustomViewForSection:kSecondSection];
        break;
    ...
    default:
        break;
使用并测试
indexPath.section
属性,例如:

switch (indexPath.section) 
    case kFirstSection:
        [self doSomethingWithCustomViewForSection:kFirstSection];
        break;
    case kSecondSection:
        [self doSomethingWithCustomViewForSection:kSecondSection];
        break;
    ...
    default:
        break;

您可以在didSelectRowatingIndexPath:方法中使用
indexPath.section
,以确定所选单元格的节

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"%i",indexPath.section);
}

上述操作将向控制台输出用户选择的部分

您可以在didselectRowatineXpath:方法中使用
indexPath.section
来确定所选单元格的部分

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"%i",indexPath.section);
}

以上内容将向控制台输出用户选择的部分,这是我使用的部分。基本上是他们说的,但如果您想在此处加载某种详细视图:

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


DetailViewController *detail = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
detail.item =(MWFeedItem *)[items objectAtIndex:indexPath.row]; 
// ...
 // Pass the selected object to the new view controller.
 [self.navigationController pushViewController:detail animated:YES];
 [detail release];

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

注意:MWFeedItem是我的一个类。你应该用你自己的

这是我用的。基本上是他们说的,但如果您想在此处加载某种详细视图:

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


DetailViewController *detail = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
detail.item =(MWFeedItem *)[items objectAtIndex:indexPath.row]; 
// ...
 // Pass the selected object to the new view controller.
 [self.navigationController pushViewController:detail animated:YES];
 [detail release];

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

注意:MWFeedItem是我的一个类。你应该使用你自己的

如果你的意思是想点击章节标题(你从
表格视图返回的文本:titleForHeaderInSection:
),那么恐怕这是不可能的


您可以使用
tableView:viewForHeaderInSection:
,并在文本顶部添加一个透明按钮。您还可以向该按钮添加一个透明文本,用于保存节索引。通过这种方式,您可以将所有节标题按钮指向同一个选择器,在该选择器中,您将拥有节(按钮的文本).

如果您的意思是想点击节标题(您从
表视图返回的文本:titleForHeaderSection:
),那么恐怕这是不可能的


您可以使用
tableView:viewForHeaderInSection:
,并在文本顶部添加一个透明按钮。您还可以向该按钮添加一个透明文本,用于保存节索引。通过这种方式,您可以将所有节标题按钮指向同一个选择器,在该选择器中,您将拥有节(按钮的文本).

您可以创建一个按钮或自定义视图,以通过委托方法插入
tableView:viewForHeaderInSection:
。此自定义视图/按钮可以响应点击。:)我已将完全相同的解决方案添加到我的答案中,与您的评论完全相同…您可以创建一个按钮或自定义视图,以通过委托方法插入
tableView:viewForHeaderInSection:
。此自定义视图/按钮可以对点击进行响应。:)我在与您的评论完全相同的时间向我的答案添加了完全相同的解决方案。。。?如果第二行中没有行,那么这个委托方法可能不会被调用,因此您不需要在这个方法中为该部分执行任何操作。是的,但是如果标题没有行,那么,如何获取该标题是否被选中??它只是一个
UIView
,因此一种方法是将
UIView
子类化,使用适当的委托方法为特定部分添加该视图,并向处理触摸手势的视图添加手势识别器:?如果第二行中没有行,那么这个委托方法可能不会被调用,因此您不需要在这个方法中为该部分执行任何操作。是的,但是如果标题没有行,那么,如何获取该标题是否被选中??它只是一个
UIView
,因此一种方法是将
UIView
子类化,使用适当的委托方法为特定部分添加该视图,并向处理触摸手势的视图添加手势识别器: