视图之间没有传递的数据控制器无法解决

时间:2014-04-21 09:23:17

标签: objective-c null push segue

我试图在两个视图控制器之间传递一个字符串,第一个名为DetailController,第二个是VideoController。它们使用push segue与按钮连接。我正在调用我的“prepareForSegue”方法,但是该字符串在VideoController中返回为null。我多年来一直坚持这个问题,仍然无法找到解决方案。任何帮助将不胜感激。

DetailController.m prepareForSegue方法

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{   NSString *myString=self.city.camera;
    NSLog(@"%@", myString);
    NSString *see=@"what is going on?";
    NSLog(@"%@", see);

    VideoController *video= (VideoController *) segue.destinationViewController;
    video.cam= self.city.camera;

}

VideoController.m

#import "VideoController.h"
#import "City.h"
#import "DetailController.h"
#import "ViewController.h"

@interface VideoController ()

@end

@implementation VideoController
@synthesize webView,city,cam;



- (void)viewDidLoad
{
    NSString *see = self.cam;
    NSLog(@"%@", see);

    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self performSelector:@selector(yourMethod) withObject:nil afterDelay:10.0];





    NSString * html = [NSString stringWithFormat:@"<img name=\"Cam\" src=\"%@\" width=\"110%%\"  height=\"100%%\" alt=\"Live Feed\" style=\"background-color: #000000\" />", cam];

    [webView loadHTMLString:html baseURL:nil];

}
-(void)yourMethod
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

这是按下按钮并发生segue时收到的消息。如果我正确地读它,那么当它应该来自不同的webView时,(null)是由与其他两个字符串相同的webView返回的吗?我完全迷失了这个问题

2014-04-21 02:20:23.093 webView[47963:1a303] http://admin:*******@192.168.1.80/video.cgi/
2014-04-21 02:20:23.094 webView[47963:1a303] what is going on?
2014-04-21 02:20:23.102 webView[47963:1a303] (null)

这是我的VideoController.h文件,因为你可以看到sam设置为strong,我错过了什么?

#import <UIKit/UIKit.h>
#import "DetailController.h"
@class City;
@interface VideoController : UIViewController{
IBOutlet UIWebView *webView;
IBOutlet UIImageView *image;



}
@property (strong,nonatomic) City *city;
@property (strong, nonatomic)NSString * cam;
@property(nonatomic,retain) UIWebView *webView;


@end

2 个答案:

答案 0 :(得分:0)

查看我的评论:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{   
   NSString *myString=self.city.camera;
   NSLog(@"%@", myString);
   NSString *see=@"what is going on?";
   NSLog(@"%@", see);

   VideoController *video= (VideoController *) segue.destinationViewController;
   // be sure that self.city.camera is has value 
   // I think you assign nil to video.cam
   video.cam= self.city.camera;
}

答案 1 :(得分:0)

确保你的&#34; cam&#34;属性没有分配弱属性,或者可能在您想要之前释放。更好的是,发布你的VideoController.h代码。