如何使用故事板在表视图中添加子视图

我正在使用故事板。 我想在表视图上select一个元素时添加一个子视图。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [arr count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } NSString *cellvalue = [arr objectAtIndex:indexPath.row]; cell.textLabel.text=cellvalue; cell.imageView.image=[UIImage imageNamed:@"1.png"]; return cell; } 

故事板对于显示您的应用程序stream程非常有用。因此,添加视图并不显示故事板中的stream程就没有意义。

故事板游戏(在视图和另一个之间的连接)有三种types,推式,模式和自定义。 如果你不想做一个模式或推动,你可以通过使用UIStoryboardSegue的执行方法来创build自己的自定义UIStoryboardSegue

  - (void)perform { // Add your own code here. [[self sourceViewController] addChildViewController:[self destinationViewController]]; } 

自定义赛段的开发人员参考 。

如果你想让它从StoryBoard中直接得到,你需要按住Ctrl从表视图单元格(原型单元格)拖动到目标视图。