【发布时间】:2011-02-24 18:35:20
【问题描述】:
我是 C++ 和 Perl 背景的新手。试图从书本中学习,但他们缺少一些 Objective-C 的核心概念。我需要一些关于此代码的帮助来拉网页:
RootViewController.m
- (void)fetchWebsite:(NSString*)website{
NSLog(@"address: %@", website);
NSString *urlAddress = website;
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webImageDisplay loadRequest:requestObj];
[webImageDisplay release];
}
- (void)viewDidLoad {
[self fetchWebsite:@"website here"];
[super viewDidLoad];
}
这段代码工作得很好,但我遇到的问题是从另一个类调用这个方法,如下面的代码:
我正确地从第二个视图控制器调用详细视图控制器,如下所示:
SubViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
switch (indexPath.row) {
case 0: {
AnotherViewController *cViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherViewController" bundle:nil];
cController.contentSizeForViewInPopover = CGSizeMake(320, 350);
[self.navigationController pushViewController:cViewController animated:YES];
[cViewController release];
break;
}
case 1: {
break;
}
}
}
然后我有一个第三个视图控制器,其中包含指向我希望在 web 视图上显示的新网页的链接。当我调用这里的方法访问RootViewController中的函数时,它似乎没有响应。
AnotherViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *itemRequested = [conusItems objectAtIndex:indexPath.row];
NSLog(@"logging: %@", itemRequested);
RootViewController *parent = [[RootViewController alloc] init];
[parent fetchWebsite:@"another website here"];
[itemRequested release];
}
我单击表格视图上的按钮,我看到代码正在使用 NSLog 在 RootViewController 中调用,但它似乎没有显示新页面。没有错误或警告,有什么想法吗?谢谢
【问题讨论】:
标签: iphone objective-c ipad uiwebview webview