最好在NSURL的下一個視圖中聲明一個屬性並設置父視圖的值。
例如,在您的DetailViewController.h設置以下代碼文件
@interface DetailViewController : UIViewController
{
NSURL *request;
}
@property (nonatomic, assign) NSURL *request;
在你DetailViewController.m文件... @synthesize請求;
並修改如下當前的代碼......
DetailViewController *newviewController=[[[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]autorelease];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:storyLink]];
newviewController.request = request;
//[newviewController.rssview loadRequest:request];
[self.navigationController pushViewController:newviewController animated:YES];
關於你的代碼...:
下面是一些你已經在你的代碼來修改缺少的東西,它會開始工作正常。
設置UIWebview控件的委託。
self.rssview.delegate = self;
[self.rssview loadRequest:self.request];
在你的DetailViewController.h中,修改以下行。
@interface DetailViewController : UIViewController <UIWebViewDelegate>
{
IBOutlet UIWebView *rssview;
NSURLRequest *request;
}
@property(nonatomic, retain, readonly)UIWebView *rssview;
@property (nonatomic, assign) NSURLRequest *request;
@end
在DetailViewController.m添加一個UIWebView的委託方法如下...
- (BOOL)webView:(UIWebView *)myWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
return YES;
}
更換繼
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
NSString * storyLink = [[stories objectAtIndex: storyIndex] objectForKey: @"link"];
// clean up the link - get rid of spaces, returns, and tabs...
storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:@"\n" withString:@""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
storyLink = [storyLink stringByAddingPercentEscapesUsingEncoding: NSStringEncodingConversionAllowLossy];
NSLog(@"link: %@", storyLink);
if(indexPath.row==0)
{
DetailViewController *newviewController=[[[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]autorelease];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:storyLink]];
//[newviewController.rssview loadRequest:request];
newviewController.request = request;
[self.navigationController pushViewController:newviewController animated:YES];
}
else
{
DetailViewController *newviewController=[[[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]autorelease];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:storyLink]];
//[newviewController.rssview loadRequest:request];
newviewController.request = request;
[self.navigationController pushViewController:newviewController animated:YES];
}
}
代碼它擺脫了幾個錯誤,但它仍然沒有加載UIWebView中的任何東西 –
http://dl.dropbox.com/u/24939871/OCVMob ile.zip 這裏是該項目,如果你想看看它,似乎沒有人能想出它 –
我已編輯答案,檢查出來。 –