首先,我非常感谢您的帮助。AppDelegate的属性意外设置为空
那么,我在两个视图中使用了三个共同的NSString对象。这些视图被嵌入式NavigationController所困扰,我的意思是我开始用SingleView编程。
在AppDelegate.h,我写
@property (weak, nonatomic) NSString *crntURL;
@property (weak, nonatomic) NSString *crntTitle;
@property (weak, nonatomic) NSString *crntHTML;
进行委派。
而在第一种观点,我有一个网页视图,写
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSString *url = [[NSString alloc] initWithString:[myWebView stringByEvaluatingJavaScriptFromString:@"document.URL"]];
NSString *title = [[NSString alloc] initWithString:[myWebView stringByEvaluatingJavaScriptFromString:@"document.title"]];
NSString *html = [[NSString alloc] initWithString:[myWebView stringByEvaluatingJavaScriptFromString:@"document.all[0].outerHTML"]];
appDelegate.crntTitle = nil;
appDelegate.crntTitle = [[NSString alloc] initWithString:title];
appDelegate.crntHTML = nil;
appDelegate.crntHTML = [[NSString alloc] initWithString:html];
appDelegate.crntURL = nil;
appDelegate.crntURL = [[NSString alloc] initWithString:url];
}
在这里,当我把NSLog的,预期的HTML源代码被倾倒。
而在第二视图(的UIViewController的一个子类),我写
- (void)viewDidLoad
{
// Do any additional setup after loading the view.
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
sourceHTML.text = appDelegate.crntHTML;
NSLog(@"%@", appDelegate.crntHTML);
NSLog(@"%@", appDelegate.crntURL);
NSLog(@"%@", appDelegate.crntTitle);
[super viewDidLoad];
}
只有crntHTML意外设置为null而crntURL和crntTitle保留值。
你有什么想法吗?
预先感谢您。
Masaru
为什么所有以'[的NSString initWithString]'电话?前几个可能是好的,但最后三个是完全多余的。 – Mac
前几个也完全是多余的。局部变量隐含地是'__strong',所以'alloc' /'initWithString'业务不需要做引用计数帮助。如果你的意思是确保你的一个变量持有一个单独的字符串副本,最好使用'copy'。 – rickster