我試圖在兩個視圖控制器之間傳遞一個字符串,第一個命名爲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
yes self.city.camera確實具有正確的值,因爲NSString * myString = self.city.camera; NSLog(@「%@」,myString);正在返回正確的字符串 – user3492592