私はRSSフィードからコンテンツを取得するニュースアプリを開発しています。 TableViewCellをクリックすると、タイトル、リンクなどを含むNSDictionaryオブジェクトを次のViewControllerに渡します。 ViewControllerではNSDictionary * itemを定義します。このようにviewcontrollerのタイトルを設定することで、値が正しく渡されることを確認できます。self.title = [item objectForKey:@ "link"];タイトルは私のUIWebViewで開こうとしているリンクを表示します。私はのUIWebViewの負荷がうまくこの@"http://somesite.com"
のようなアドレスを割り当てるが、ときUIWebViewでページを読み込めません
はここで、今私のViewControllerの実装
//
// NewsDetailViewController.m
// NewsApp2
//
// Created by Marco Soria on 12/27/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "NewsDetailViewController.h"
@implementation NewsDetailViewController
@synthesize item, itemTitle, itemDate, itemSummary;
-(id)initWithItem:(NSDictionary *)theItem{
if(self = [super initWithNibName:@"NewsDetail" bundle:[NSBundle mainBundle]]){
self.item = theItem;
self.title = [item objectForKey:@"link"];
}
return self;
}
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
}
return self;
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
NSString *urlAddress = [self.item objectForKey:@"link"];
NSURL *baseURL = [[NSURL URLWithString: urlAddress] retain];
NSURLRequest *request = [NSURLRequest requestWithURL:baseURL];
[self.itemSummary loadHTMLString:urlAddress baseURL:nil];
[self.itemSummary loadRequest:request];
[baseURL release];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
である私がこれを行うとき:NSString *urlAddress = [self.item objectForKey:@"link"];
それは決して負荷を。私が述べたように、[self.item objectForKey:@"link"];
の値はナビゲーションバーのタイトルに表示されてから有効なURLです。
この場合、[self.itemSummary loadHTMLString:urlAddress baseURL:nil]; UIWebViewはurlを表示します。これは、urlAddressに正しいURLがあることを確認する別の方法です。
私は間違っていますか?
新しいビューコントローラを作成し、項目を渡すコードを表示します。すべてのコードを正確に表示します。ここで質問を編集し、そのコードを最後に追加するだけです。 –
ナビゲーションバーのタイトルとして表示することは、必ずしも有効なURLの証拠ではありません。あなたがNSLog(またはブレークポイントを設定し、それをpo)すれば、どうなるでしょうか? –
私はNSLogとbaseURLがnilを返していることがわかりましたが、urlAddressは "有効な" URLを持っていますので、私はそうします NSURL * baseURL = [[NSURL URLWithString:urlAddress] retain]; baseURLが正しく初期化されていません。おそらくエンコーディングで何かを行う必要がありますか? –