码迷,mamicode.com
首页 > 移动开发 > 详细

iOS开发之点击tableViewCell,显示详情

时间:2016-06-15 22:10:34      阅读:587      评论:0      收藏:0      [点我收藏+]

标签:

介绍一种在storyboard上拖控件创建segue的方法。

 

 

// 首先去翻译了下Segue

// 来源:https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/UsingSegues.html

// 定义:Segue表示storyboard文件中两个ViewController之间的转换(?)。通常由A视图控制器的按钮、表格行或手势指向B视图控制器。

// 触发:由UIKit实现,可使用notifications在A、B间传输数据。segue被触发后工作流程如下

技术分享

提供shouldPerformSegueWithIdentifier:sender:方法中止跳转所需的步骤,如不新建segue和B;

提供prepareForSegue:sender:方法传输数据。

// 类型:原表如下,几个segue的区别是:show是把B堆在A上,detail用B替换A,Modally用模版显示B,Popover用B作弹窗。

Table 9-1Adaptive segue types

Segue type

Behavior

Show (Push)

This segue displays the new content using the showViewController:sender: method of the target view controller. For most view controllers, this segue presents the new content modally over the source view controller. Some view controllers specifically override the method and use it to implement different behaviors. For example, a navigation controller pushes the new view controller onto its navigation stack. 

UIKit uses the targetViewControllerForAction:sender:method to locate the source view controller.

Show Detail (Replace)

This segue displays the new content using the showDetailViewController:sender: method of the target view controller. This segue is relevant only for view controllers embedded inside a UISplitViewController object. With this segue, a split view controller replaces its second child view controller (the detail controller) with the new content. Most other view controllers present the new content modally.

UIKit uses the targetViewControllerForAction:sender:method to locate the source view controller.

Present Modally

This segue displays the view controller modally using the specified presentation and transition styles. The view controller that defines the appropriate presentation context handles the actual presentation. 

Present as Popover

In a horizontally regular environment, the view controller appears in a popover. In a horizontally compact environment, the view controller is displayed using a full-screen modal presentation.

// 步骤

1. 选中cell,关联cell与B,segue类型选择selection show (detail)

技术分享

2. 在A对应的Controller中覆盖prepareForSegue方法

class AController: UIViewController, UITableViewDataSource,UITableViewDelegate {

    // ...

    // 目前只有一个segue,所以没有判断viewControllerId,产生错误再学怎么区分

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        let index : Int = (self.table.indexPathForSelectedRow?.row)!

        let data:VideoSummary = videoSummaries[index]

        let view : BController = segue.destinationViewController as! VideoViewController

        view.selectedVideo = data

    }

}

3. 在B对应的Controller中添加selectedVideo属性

class BController: UIViewController , UITableViewDataSource,UITableViewDelegate {

    var selectedVideo : VideoSummary! // 注意感叹号

    //...

}

// 成功。

 

iOS开发之点击tableViewCell,显示详情

标签:

原文地址:http://www.cnblogs.com/yinkw/p/5589008.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!