这个网站的新手,但是在过去几个小时尝试修复我知道必须非常简单的东西后,我的脑袋绝对会让我失望。
短篇小说:
除了将每行的URL推送到第二个控制器中的webView之外,我还能正常工作。它推送视图,但URL没有被发送到第二个控制器,因此webView是空白的。我在代码中的NSLogs表明URL也正在成功创建,那么我需要做些什么才能让newsWebView处理URL?
tableView.m
- (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:@""];
NSLog(@"storyLink: %@", storyLink);
if (storyLink != nil && ![storyLink isEqualToString:@""]) {
// Wrapping the troublesome call with logs so you should be able to see if this is the line that is killing your app
NSLog(@"about to create url");
NSURL *url = [NSURL URLWithString:storyLink];
NSLog(@"creating url was successful");
//URL Request Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView
newsWebView *detailViewController = [[newsWebView alloc] initWithNibName:@"newsDetailWebView" bundle:nil];
//detailViewController.item = [[stories objectAtIndex: storyIndex] objectForKey: @"link"];
[self.navigationController pushViewController:detailViewController animated:YES];
//[detailViewController loadRequest:requestObj];
[detailViewController release];
}
}
那么,我需要在newsWebView.m中添加到viewDidLoad?或者,就此而言,我的tableView的didSelectRowAtIndexPath有什么问题?
newsWebView.m
- (void)viewDidLoad {
}
非常非常感谢你。我需要一些Advil!
答案 0 :(得分:3)
在newsWebView类中有一个实例变量说urlObject
的{{1}}类型。确保添加NSUrl
和@property
对象。
然后
@synthesize
并在newsWebView.m
中newsWebView *detailViewController = [[newsWebView alloc] initWithNibName:@"newsDetailWebView" bundle:nil];
newsWebview.urlObject = url;
[self.navigationController pushViewController:detailViewController animated:YES];
//[detailViewController loadRequest:requestObj];
[detailViewController release];