2014-04-21 89 views
0

我試圖在兩個視圖控制器之間傳遞一個字符串,第一個命名爲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 *[email protected]"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作爲其他兩個字符串返回,當它應該來自不同的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設置爲強,我失去的東西嗎?

#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 

回答

0

見我的評論:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    NSString *myString=self.city.camera; 
    NSLog(@"%@", myString); 
    NSString *[email protected]"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; 
} 
+0

yes self.city.camera確實具有正確的值,因爲NSString * myString = self.city.camera; NSLog(@「%@」,myString);正在返回正確的字符串 – user3492592

0

確保您的「凸輪」屬性不會有微弱的屬性分配,或者你想之前它可能被釋放。更好的是,發佈VideoController.h代碼。

+0

我已經發布了我的VideoController.h代碼,因爲您可以看到它設置爲強壯。還有什麼我失蹤的? – user3492592

+0

經過半小時的爭鬥,我仍然無法重新創建您的bug。無論我對代碼做些什麼瘋狂的事情,「凸輪」數據都會傳遞得很好並被正確記錄。您可能想要「清理」並重新構建,或關閉並重新啓動Xcode,或重新啓動Mac。 –

+0

非常感謝你的努力,我看不出爲什麼我會得到這個bug。我會繼續努力,看看我能否解決它。 – user3492592

相關問題