Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.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
Ios UITableView,单击行时如何处理?_Ios_Objective C_Uitableview - Fatal编程技术网

Ios UITableView,单击行时如何处理?

Ios UITableView,单击行时如何处理?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我似乎找不到如何在单击一行时显示另一个“UIViewController”视图。所以,就像单击该行一样,它会转到下一个视图并显示有关该行的更多信息 我想我需要使用类似于-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(nsindepath*)indepath委托的东西。然后我的第二个问题是如何将该行中的数据(如标题)传递给下一个视图控制器 谢谢 就像@rmaddy所说的,如果你做一些研究会更好,这是非常基本的,我建

我似乎找不到如何在单击一行时显示另一个“UIViewController”视图。所以,就像单击该行一样,它会转到下一个视图并显示有关该行的更多信息

我想我需要使用类似于
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(nsindepath*)indepath
委托的东西。然后我的第二个问题是如何将该行中的数据(如标题)传递给下一个视图控制器

谢谢

就像@rmaddy所说的,如果你做一些研究会更好,这是非常基本的,我建议你:


为伟大的教程网站,他们真的有你需要的一切

下面是一个假设的例子:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
    MyCustomViewController *vc = [[MyCustomViewController alloc]initWithTitle:selectedCell.textLabel.text];
    // Assuming your UITableViewDelegate has a navigationController
    [self.navigationController presentViewController:vc animated:YES completion:nil];
}

如果您使用的是故事板:

h

m

您可能已经有了这个方法,如果是这样的话,请在其中添加代码。此方法在segue即将执行时调用

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:@"nameOfYourSegue"]){

    //Pass data from one controller to the next
    [[segue destinationViewController] setRowIndex:selectedRow];
}

}
selectedRow将具有所选行的索引,其中0是第一行

在下一个视图控制器的类中:

h

m

完成此操作后,您可以编辑此代码以传递一组信息。

使用以下方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
您可以通过索引路径获取单元格:

  UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
守则:

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

          UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    }
获取单元格数据后,您可以使用它 对问题2的答复:

您可以在interface builder中通过顺序将您的单元格与下一个vc连接,并在方法prepareforseque中将数据传递给

segue.DestinationViewController.yourPoperty 现在在viewdidload方法中:


self.title=self.property

是的,这是正确的委托方法。请做些调查。关于如何做到这一点,有无数的教程和现有的讨论。提示:创建一个新的Xcode项目并选择iOS“Master Detail Application”模板。这为您提供了可用的示例代码。“//假设您的UITableViewDelegate有一个navigationController”,这是什么意思?警告:在演示过程中尝试打开演示!当我点击表格中的一个单元格时,会出现这种情况,你知道为什么吗?很难说,但是当我试图一次制作太多动画时,就会出现这种错误。当我试图关闭两个具有模态分段的视图控制器时,我得到了这个警告,因为它试图同时从一个视图控制器到下一个视图控制器设置动画。这就是为什么我从现在开始使用导航控制器,因为我可以简单地弹出到任何视图控制器。如果在将数据从视图控制器传递到视图控制器时遇到问题,请检查以下问题:
- (void)setRowIndex:(int)rowIndex;
- (void)setRowIndex:(int)rowIndex
{
     //assign your variable to rowIndex

}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
  UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
 - (void)tableView:(UITableView *)tblView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    {

          UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    }