将数据从一个viewcontroller传递到另一个
我将两个视图控制器子类化。
第一个应该传递数据,NSUrl对象传递给第二个。
.m的第一个:
NSURL *temp = [NSURL URLWithString:@"http://example.com"]; UIViewController *presentationsFullScreen_ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PresentationsFullScreen_ViewController"]; presentationsFullScreen_ViewController.urlToUse = temp;
.h的第二个:
#import @interface PresentationsFullScreen_ViewController : UIViewController { NSURL *urlToUse; } @property (nonatomic,retain) NSURL *urlToUse;
它显然不起作用而且没有编译,基本上告诉我,我没有将它子类化,并且在UIViewController上找不到属性urlToUse。
我如何正确子类?
谢谢!
这是正确的代码
PresentationsFullScreen_ViewController *presentationsFullScreen_ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PresentationsFullScreen_ViewController"]; presentationsFullScreen_ViewController.urlToUse = temp;
解:
不要忘记导入.h:
#import "PresentationsFullScreen_ViewController"
并且不要使用UIViewController实例化对象,而是使用子类的名称实例化:
PresentationsFullScreen_ViewController *presentationsFullScreen_ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PresentationsFullScreen_ViewController"];
- PhoneGap 2.0在XCode中不显示console.log
- – (void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error – Method is not call
- 何时使用__bridge_transfer和__bridge
- 如何从我的应用程序打开缩短的Google Maps URL?
- 带有ScrollView的IOS UICollectionView
- renderincontext内存泄漏,如果不在主线程上使用
- iOS应用程序平均在后台运行多久,直到它被杀死?
- 自定义UITableViewCell委托不调用方法
- iOS UIActivityViewController使用UIActivityItemProvider“忘记”项目
- 在Objective-C中parsing以@和#开头的string
- 在UIPageViewController中,当“pageViewController:viewControllerBeforeViewController”被调用?