performSegueWithIdentifier 和 sharedData

performSegueWithIdentifier and sharedData(performSegueWithIdentifier 和 sharedData)
本文介绍了performSegueWithIdentifier 和 sharedData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我希望我问的不是已经回答的问题(但我没有找到答案,所以希望我没有).

I hope I'm not asking something that's been already answered (but I found no answer to this, so hopefully I'm not).

我在当前的 xcode 版本中有一个应用程序,使用 segues 和 navigationController.我需要将数据从一个视图传递到另一个视图 - 最简单的方法是什么?我遇到了一些可能与 performSegueWithIdentifier 方法挂钩的 sharedData 东西,但不知道如何使用它(或者这样做是否是正确的选择).

I have an app in the current xcode version, using segues and navigationController. I need to pass data from one view to the other - what's the easiest way to do this? I ran onto some sharedData thing that could be possibly hooked onto the performSegueWithIdentifier method but don't know how to use it (or whether it is the right choice to do it like this).

谢谢

推荐答案

一个segue有两个视图控制器:sourceViewControllerdestinationViewController.当 UIKit 执行 segue 时,它会向源 VC 发送 prepareForSegue:sender: 消息.您可以在视图控制器子类中重写该方法以将数据传递给目标 VC.

A segue has two view controllers: sourceViewController and destinationViewController. When UIKit executes a segue, it sends a prepareForSegue:sender: message to the source VC. You can override that method in your view controller subclass to pass data to the destination VC.

例如,假设您有一个带有电影表视图的主视图控制器,并且当用户单击表视图中的一行时,您希望转到电影的详细视图控制器.

For example, suppose you have a master view controller with a table view of movies, and when the user clicks a row in the table view, you want to segue to a detail view controller for the movie.

@implementation MasterViewController

...

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    DetailViewController *detailVC = segue.destinationViewController;
    NSIndexPath *selectedPath = [self.tableView indexPathForSelectedRow];
    detailVC.movie = [self movieForIndexPath:selectedPath];
}

Interface Builder Storyboard 简介中对此进行了解释来自 WWDC 2011 的视频.

This is explained in the Introducing Interface Builder Storyboarding video from WWDC 2011.

另外值得注意的是,当segue的来源是table view cell,或者table view cell的附属按钮时,prepareForSegue:sender:sender参数是表格视图单元格.

It's also worth noting that when the segue's origin is a table view cell, or the accessory button of a table view cell, the sender argument of prepareForSegue:sender: is the table view cell.

这篇关于performSegueWithIdentifier 和 sharedData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)