OStack程序员社区-中国程序员成长平台

标题: iphone - 当用户单击一行时,如何移动到另一个 View Controller ? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 16:45
标题: iphone - 当用户单击一行时,如何移动到另一个 View Controller ?

我是 iPhone 开发的新手,我想在用户单击特定行时转到另一个页面。所以,如果他们点击第一行,我希望页面重定向到第一个 View Controller ,依此类推。每行都有自己的 View Controller 。



Best Answer-推荐答案


首先,您不需要为每一行设置不同的 View Controller (除非您有充分的理由这样做)。

正确的方法是设置 1 个 View Controller ,该 Controller 将适合原始中的所有单元格并根据所选行更改其数据。

你这样做的方式是:

in the - DidSelectRowAtIndexPath function in your implementation file you shuld:

    - (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath
     {

//allocate your view controller
         DetailedViewController *detailedViewController = [[DetailedViewController alloc] init];

 //send properties to your view controller
         detailedViewController.property1 = someProperty1;
         detailedViewController.property2 = someProperty2;

 //push it to the navigationController
         [[self navigationController] pushViewController:detailedViewController animated:YES];
         [detailedViewController release];
    }

我确实建议您从使用苹果示例开始,它们很棒,而且数量很多:

http://developer.apple.com/library/ios/#samplecode/TableViewSuite/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40007318

祝你好运

关于iphone - 当用户单击一行时,如何移动到另一个 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5102122/






欢迎光临 OStack程序员社区-中国程序员成长平台 (http://ostack.cn/) Powered by Discuz! X3.4