//
// ViewController.m
// WebViewDemo
//
// Created by Vu Van Tiep on 1/15/13.
// Copyright (c) 2013 Vu Van Tiep. All rights reserved.
//
#import "ViewController.h"
#import "WebViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:@"GoogleSegue"]){
WebViewController *desView = (WebViewController*) [segue destinationViewController];
UIWebView *webView = desView.webView;
if([webView respondsToSelector:@selector(loadRequest:)] || webView != nil){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
//webView is nil
}
}
@end
//
// WebViewController.m
// WebViewDemo
//
// Created by Vu Van Tiep on 1/15/13.
// Copyright (c) 2013 Vu Van Tiep. All rights reserved.
//
#import "WebViewController.h"
@interface WebViewController ()
@end
@implementation WebViewController
@synthesize webView;
- (void)viewDidLoad
{
[super viewDidLoad];
self.webView.scalesPageToFit = YES;
}
@end
@interface WebViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@end
当我使用[segue destinationViewController]时,我得到了WebViewControlller对象,但是当我访问该对象的webView属性时,它是零
有人可以向我解释一下吗? :(
谢谢!
答案 0 :(得分:1)
您的WebViewController视图尚未初始化。你需要告诉它初始化。在行
后执行WebViewController *desView = (WebViewController*) [segue destinationViewController]; }
添加行
[desView view];
这与Use destinationViewController button in a custom segue中的问题相同。虽然这一定是一个非常普遍的问题,但我发现很难找到有关此问题的信息。