我试图通过prepareForSegue方法在2个ViewControllers之间传递一些数据,但我的segue.destinationViewController总是错误的类,所以我得到一个“无法识别的选择器发送到实例”
segue.destinationViewController应该是一个WebViewController,是一个UIViewController。
启用ARC。
以下是我的一些代码:
NewsTableViewController.h
#import "WebViewController.h"
@interface NewsTableViewController : UITableViewController {
}
@end
NewsTableViewController.m
@implementation NewsTableViewController
//some code
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"showNewsWebView"]) {
WebViewController *webViewConroller = segue.destinationViewController ;
// here it prints UIViewController instead of WebViwController*
NSLog(@"%@",[webViewConroller class]);
//here i get the error, because setUrlAsString is not defined for UIViewController but WebViewController
[webViewConroller setUrlAsString:[NSString stringWithString:@"www.apple.com"]];
}
}
WebViewController.h
@interface WebViewController : UIViewController{
IBOutlet UIWebView * webView;
NSString *urlAsString;
}
@property (nonatomic) NSString * urlAsString;
-(void)setUrlAsString:(NSString *) string;
WebviewController.m
#import "WebViewController.h"
@interface WebViewController ()
@end
@implementation WebViewController
@synthesize urlAsString;
-(void)setUrlAsString:(NSString *) string{
self.urlAsString = string;
NSLog(@"%@",urlAsString);
}
//some other code