【问题标题】:connect uitableviewcells to diffrent viws via segue通过 segue 将 uitableview 单元格连接到不同的视图
【发布时间】:2012-08-13 14:48:38
【问题描述】:

我以编程方式创建了一个 UITableView,其中包含连接到故事板中其他视图的不同单元格和部分,如下图所示:

我的问题是:

如何将这 3 个单元格连接到这些不同的视图,请您帮帮我

提前致谢!

这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *key = [[self sectionKeys] objectAtIndex:[indexPath section]];
NSArray *contents = [[self sectionContents] objectForKey:key];
NSString *contentForThisRow = [contents objectAtIndex:[indexPath row]];

static NSString *CellIdentifier = @"CellIdentifier";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
reuseIdentifier:CellIdentifier];
}

[[cell textLabel] setText:contentForThisRow];
return cell;

}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
_selectedIndex = indexPath.row;
[self.tableView reloadData];

}

编辑: 当我使用此方法时,即使用户选择缺席单元格,它也只会加载 WorkTime 视图, 有谁知道为什么?

  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
  _selectedIndex = indexPath.row;
[self.tableView reloadData];
//maybe you could use a switch/case here, to assign the correct string to the segue identifier.
 switch (indexPath.row){
    case 0:
        [self performSegueWithIdentifier:@"test" sender:self];
        break;
    case 1:
        [self performSegueWithIdentifier:@"set" sender:self];
        break;
    case 2:
        [self performSegueWithIdentifier:@"get" sender:self];
        break;
 }
 }

【问题讨论】:

标签: objective-c xcode uitableview storyboard


【解决方案1】:

您的最后一种方法是您想走的路,但从外观上看,您需要检查indexPath.section 而不是indexPath.row

【讨论】:

  • @justin 我在我的回答中的意思是你在didSelectRowAtIndexPath 中拥有它的方式或多或少是正确的,但你需要检查该部分,而不是查看其余部分的行你的代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-06-14
  • 2023-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多