[英]Passing data from some TextFields in one ViewController to a TextView in another ViewController
[英]Passing data from one viewcontroller to another
我將兩個視圖控制器歸為一類。
第一個應該將數據,一個NSUrl對象傳遞給第二個。
.m的第一個:
NSURL *temp = [NSURL URLWithString:@"http://example.com"];
UIViewController *presentationsFullScreen_ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PresentationsFullScreen_ViewController"];
presentationsFullScreen_ViewController.urlToUse = temp;
第二個.h:
#import <UIKit/UIKit.h>
@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"];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.