TableView这个控件在iOS的开发中非常的常见,他可以较好的展示一个层级结构。这里主要介绍,在点击某个条目的时候,如何进行跳转的下一个界面。以下是官方的关于这个跳转如何去实现,和如何去传递数据的过程。

  

Storyboards make it easy to pass data from one scene to another via the prepareForSegue:sender: method of the UIViewController class. This method is called when the first scene (the source) is about to transition to the next scene (the destination). The source view controller can implement prepareForSegue:sender: to perform setup tasks, such as passing information to the destination view controller about what it should display in its table view. Listing - shows one implementation of this method.

Storyboards利用func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!)将数据从一个界面传输到另外一个界面。这个函数在源界面切换到目标界面的时候会调用。所以在源View Controller中可以重载func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!)这个方法,在该方法内完成将数据传送到目的View Controller。下面就是这个函数一般的实现方式。
(Objective-C)
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"ShowDetails"]) { MyDetailViewController *detailViewController = [segue destinationViewController];
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
detailViewController.data = [self.dataController
objectInListAtIndex:indexPath.row];
} } (Swift)

func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {

if(segue.identifier == "ShowDetails"){

var detailViewController:MyDetailViewController ! = segue.destinationViewController as MyDetailViewController

       var index = tableView.indexPathForSelectedRow()

detailViewController.data = dataController[index!.row]

}

}

 
A segue represents a one-way transition from a source scene to a destination scene. One of the consequences of this design is that you can use a segue to pass data to a destination, but you can’t use a segue to send data from a destination to its source. To solve this problem, you create a delegate protocol that declares methods that the destination view controller calls when it needs to pass back some data.

Segue是条从源界面到目标界面的一条路。你可以通过Segue将数据从源界面->目标界面。

以上的过程是在tableViewCell与DetailView界面建立Segue连接的情况下,并且设置了Segue的identifer。

Segue是完全在Storyboard可以拖拽建立,比较简单,关于如何建立Segue请网上查找下资料。

  

点击TableView中某行进入下一级界面(Swift)的更多相关文章

  1. securecrt中vim行号下划线问题及SecureCRT里root没有高亮的设置,修改linux终端命令行颜色

      背景:在用raspberry用SecureCRT下的vim打开文件时出现用set nu时行有下划线,于是找了下解决办法,如下:vim行号下划线问题在vim中发现开启显示行号(set number) ...

  2. secureCRT中vim行号下划线问题

    在vim中发现开启显示行号(set number)或语法高亮(syntax on)时,发现文档中很多地方都有下划线,对视觉产生极大干扰.开始还以为是vim的某个配置造成的,后来发现真正的元凶是secu ...

  3. iOS 横屏模态进入下一级界面, 竖屏退出

    首先  Deployment Info 设置 除了  Upside Down 都勾选 然后,在AppDelegate.h 文件中 添加属性 @property(nonatomic,assign)NSI ...

  4. Tools下的mdscongiguer 文件中 43行 oracle 配置 发现需要连接库 -lclntsh libclntsh.so 库是个什么东西呢?

    Tools下的mdscongiguer     文件中 43行  oracle 配置      发现需要连接库 -lclntsh      libclntsh.so 库是个什么东西呢? 分想一个知乎网 ...

  5. 【原】Mac下统计任意文件夹中代码行数的工

    [链接][原]Mac下统计任意文件夹中代码行数的工http://www.cnblogs.com/wengzilin/p/4580646.html

  6. iOS利用响应链机制点击tableview空白处关闭键盘-可以作为参考

    http://www.jianshu.com/p/9717b792599c   是原文地址 处理关闭键盘的做法一般分为两种:1.放弃第一响应者身份:2.当前视图结束编辑.通常情况下只要我们在合适的时机 ...

  7. 命令行环境下简单实用的工具——重定向&管道

    如果你对管道和重定向应用自如了,无需继续往下看.本文虽然以windows上cmd命令行环境演示,但同样适用于Unix/Linux等平台. 引言 关于管道和重定向,最初是在刘汝佳的<算法竞赛入门经 ...

  8. 在WPF中自定义控件(3) CustomControl (下)

    原文:在WPF中自定义控件(3) CustomControl (下)   在WPF中自定义控件(3) CustomControl (下)                                 ...

  9. Tableview中Dynamic Prototypes动态表的使用

    Tableview时IOS中应用非常广泛的控件,当需要动态的添加多条不同的数据时,需要用动态表来实现,下面给出一个小例子,适用于不确定Section的数目,并且每个Section中的行数也不同的情况, ...

随机推荐

  1. 避免使用CreateThread函数,导致的内存泄露

    原文链接:http://blog.csdn.net/solosure/article/details/6262877

  2. docker学习(二)

    1 镜像 docker使用联合加载技术,一次同时加载多个文件系统,在外面只能看到一个文件系统 docker使用写时复制,每个只读镜像层都是只读的,也永远不会发生变化,建立一个新容器,会构建一个镜像栈, ...

  3. 2搭建Android开发环境

    这一章主要是讲解如何搭建Android开发环境,需要准备的工具有: (1)   JDK6或以上的版本: (2)   Eclipse (3)   ADT(用于开发Android应用程序) (4)   C ...

  4. win7启动文件修复

    1:在xp下运行bcdedit.exe(这软件在windows 7的系统盘下 就在你的c:\windows\system32\这里2:将这软件复制到c盘根目录下3:进入命令提示符 输入 c:4:输入 ...

  5. 线性回归的Spark实现 [Linear Regression / Machine Learning / Spark]

    1- 问题提出 2- 线性回归 3- 理论推导 4- Python/Spark实现 # -*- coding: utf-8 -*- from pyspark import SparkContext t ...

  6. 使用OrderBy对List<Person>集合排序

    string sortOrder = Request.QueryString["sortOrder"];   string sortField = Request.QueryStr ...

  7. Windows下zlib库和libPng库的编译和使用

    关于zlib库和libpng是干嘛的,我就不说了,度娘和谷歌都能告诉你.这里主要记录下windows下如何利用vs2010编译和使用这两个库. 一.zlib库的编译 首先要下载这个库,这个谷歌和百度也 ...

  8. js ajax乱码查看\u8fdb\u53e3

    document.write('\u8fdb\u53e3') //在页面上看乱码转为中文 或在按F12 在console里查看 直接打'\u8fdb\u53e3'

  9. 显示当前一个礼拜的日期 new Date()

    显示这一礼拜的日期 html: <div class="month"></div> <table> <tr> <th>日 ...

  10. 日志处理--Logo4Net与文件的并发处理

    本文参考自:http://www.cnblogs.com/jiekzou/ 多线程操作同一个文件时会出现并发问题.解决的一个办法就是给文件加锁(lock),但是这样的话,一个线程操作文件时,其它的都得 ...