点击TableView中某行进入下一级界面(Swift)
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)的更多相关文章
- securecrt中vim行号下划线问题及SecureCRT里root没有高亮的设置,修改linux终端命令行颜色
背景:在用raspberry用SecureCRT下的vim打开文件时出现用set nu时行有下划线,于是找了下解决办法,如下:vim行号下划线问题在vim中发现开启显示行号(set number) ...
- secureCRT中vim行号下划线问题
在vim中发现开启显示行号(set number)或语法高亮(syntax on)时,发现文档中很多地方都有下划线,对视觉产生极大干扰.开始还以为是vim的某个配置造成的,后来发现真正的元凶是secu ...
- iOS 横屏模态进入下一级界面, 竖屏退出
首先 Deployment Info 设置 除了 Upside Down 都勾选 然后,在AppDelegate.h 文件中 添加属性 @property(nonatomic,assign)NSI ...
- Tools下的mdscongiguer 文件中 43行 oracle 配置 发现需要连接库 -lclntsh libclntsh.so 库是个什么东西呢?
Tools下的mdscongiguer 文件中 43行 oracle 配置 发现需要连接库 -lclntsh libclntsh.so 库是个什么东西呢? 分想一个知乎网 ...
- 【原】Mac下统计任意文件夹中代码行数的工
[链接][原]Mac下统计任意文件夹中代码行数的工http://www.cnblogs.com/wengzilin/p/4580646.html
- iOS利用响应链机制点击tableview空白处关闭键盘-可以作为参考
http://www.jianshu.com/p/9717b792599c 是原文地址 处理关闭键盘的做法一般分为两种:1.放弃第一响应者身份:2.当前视图结束编辑.通常情况下只要我们在合适的时机 ...
- 命令行环境下简单实用的工具——重定向&管道
如果你对管道和重定向应用自如了,无需继续往下看.本文虽然以windows上cmd命令行环境演示,但同样适用于Unix/Linux等平台. 引言 关于管道和重定向,最初是在刘汝佳的<算法竞赛入门经 ...
- 在WPF中自定义控件(3) CustomControl (下)
原文:在WPF中自定义控件(3) CustomControl (下) 在WPF中自定义控件(3) CustomControl (下) ...
- Tableview中Dynamic Prototypes动态表的使用
Tableview时IOS中应用非常广泛的控件,当需要动态的添加多条不同的数据时,需要用动态表来实现,下面给出一个小例子,适用于不确定Section的数目,并且每个Section中的行数也不同的情况, ...
随机推荐
- iPad用户使用Mac和Windows应用软件-记Parallels Access使用体验
iPad用户使用Mac和Windows应用软件-记ParallelsAccess使用体验 用ipad远程连接win系统已不是新鲜事情,我们可以使用TeamViewer和OnLiveDesktopPlu ...
- LoadRunner脚本 《第二篇》
一.基础函数简介 在VU左边导航栏中,有三个LoadRunner框架函数,分别是vuser_init().Action().vuser_end().这三个函数存在于任何Vuser类型的脚本中. vus ...
- sql 时间向减函数
select datediff(d, ( select isnull( ( select v.VerifyDate from T_VerifySituation v where Orde ...
- GUI异步编程之BackgroundWorker类
GUI编程中,经常需要另建一个线程,在后台运行以完成某项工作,并不时地与界面主线程进行通信,以改变界面显示.BackgroundWorker类为此而生. BackgroundWorker类的主要成员: ...
- 如何获取tableview中当前选中的cell
当我们点击某个cell时,会执行下面这个方法,方法中调用另一方法执行具体操作: - (void)tableView:(UITableView *)tableView didSelectRowAtInd ...
- shell脚本中切换用户并执行命令
1.切换用户并执行命令 su 用户名 -c "命令" 2.切换用户并执行脚本 su 用户名 -s /bin/bash 脚本路径 3.切换用户并执行命令集su 用户名 << ...
- MySQL连接语法
http://www.cnblogs.com/hanzhaoxin/p/3590642.html 内连接:INNER JOIN 内连接为 两个表中必须都同时满足条件 内连接,即最常见的等值连接自然连 ...
- WAMP环境下访问PHP提示下载PHP文件
原因是服务器没有加载到PHP文件 到http.conf下加载 AddType application/x-httpd-php .php AddType application/x-httpd-php ...
- 用Lambda表达式操作List集合
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- firefox 扩展开发笔记(三):高级ui交互编程
firefox 扩展开发笔记(三):高级ui交互编程 前言 前两篇链接 1:firefox 扩展开发笔记(一):jpm 使用实践以及调试 2:firefox 扩展开发笔记(二):进阶开发之移动设备模拟 ...