当用户单击一行时,如何移动到另一个视图控制器? [英] How can I move to another view controller when the user clicks on a row?

查看:88
本文介绍了当用户单击一行时,如何移动到另一个视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iPhone开发的新手,当用户点击特定行时,我想移动到另一个页面。所以,如果他们点击第一行,我想要的页面重定向到第一个视图控制器,等等。每一行都有自己的视图控制器。

解决方案

首先你不需要为每一行设置不同的视图控制器除非你有一个非常好的理由这样做)。



正确的方法是设置1视图控制器,将适合原始的所有单元格,并更改其数据

  >在你的实现文件中的 -  DidSelectRowAtIndexPath函数中:

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

//分配你的视图控制器
DetailedViewController * detailedViewController = [[DetailedViewController alloc] init];

//将属性发送到视图控制器
detailedViewController.property1 = someProperty1;
detailedViewController.property2 = someProperty2;

//将其推送到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



祝你好运


I am new to iPhone development, and I want to move to another page when the user clicks on a particular row. So, if they click on first row, I want the page to redirect to the first view controller, and so on. Each row has its own view controller.

解决方案

first of all you don't need to set different view controller for each row (unless you have a very good reason for doing that).

the correct way is to set 1 view controller that will fit all the cells in the raws and change its data according to the selected row.

the way you do that is:

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

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)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];
    }

i do recommend that you will start by using apple examples, they are great and there are a lot of them :

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

Good luck

这篇关于当用户单击一行时,如何移动到另一个视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆