我是新手,因爲我來自C++和Perl背景。試圖從書本中學習,但他們錯過了Objective-C的一些核心概念。我需要這個代碼一些幫助拉網頁:iPad iPhone:從另一個視圖控制器類調用Webview
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的,但它似乎並沒有顯示新頁。沒有錯誤或警告,任何想法?謝謝
對不起因爲沒有詳細說明。我試圖做到這一點http://mobiforge.com/designing/story/using-popoverview-ipad-app-development但第三視圖控制器在它似乎並不能正確調用從根控制器的webview拉起新一頁。 – 2011-02-24 19:34:33