2011-06-15 38 views
0

我的設置:帶有選項卡欄控制器(包括選項卡欄)的MainWindow和兩個UIViewController s,都被分配到延伸UIViewController的同一接口。這個自定義接口實現了IBOutlet Webview和一個加載URL的void。在主要.m上的didSelectViewController我嘗試撥打LoadURL'UITabBarController'可能不會響應'-method'

的.m視圖控制器的

@implementation MyTabBarController 
@synthesize webView; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
return [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
} 

- (void) LoadURL: (NSString*)s { 
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:s]]]; 
} 

- (void)dealloc { 
[super dealloc]; 
} 
@end 

視圖控制器

#import <UIKit/UIKit.h> 

@interface MyTabBarController : UIViewController { 
IBOutlet UIWebView *webView; 
} 

- (void) LoadURL: (NSString*)s; 

@property (nonatomic, retain) UIWebView *webView; 

@end 

的.m主窗口

- (void) tabBarController: (UITabBarController *) myController didSelectViewController: (UIViewController *) viewController { 
[myController LoadURL:@"http://google.com"]; // WARNING 
} 

我把斷點上每個的.H空隙,他們會被召喚。但我的webView不顯示任何內容。除此之外

我得到了2個警告:

'UITabBarController' may not respond to '-LoadURL:' 
Semantic Issue: Method '-LoadURL:' not found (return type defaults to 'id') 
+0

你定義的視圖控制器頭文件使用loadURL方法的一個子類?如果是這樣,你怎麼定義它? – csano 2011-06-15 22:39:43

+0

感謝您的回覆。我編輯了我的文章以包含.h文件。 – Blisra 2011-06-15 22:47:41

回答

0

最有可能你要投它,如果你是確保它不是一個UIViewController但

[(MyTabBarController*)myController LoadURL:@"http://google.com"] 
+0

謝謝,是的,我已經想到了。它是UIViewController的一個子類。但我得到:'MyTabBarController'未聲明(首次在此函數中使用) – Blisra 2011-06-15 22:30:10

+0

你沒有導入它 – vikingosegundo 2011-06-15 22:31:18

+0

你能告訴我如何導入它嗎? – Blisra 2011-06-15 22:32:08

0

-LoadURL:方法不UITabBarController定義。也許你的意思是做

[self LoadURL:@"http://google.com"]; 

+0

更有可能'[viewController LoadURL:'... – 2011-06-15 22:15:49

+0

感謝您的回覆。 @Dave我不明白,對不起:我自己並沒有爲我工作。也許是因爲-LoadURL不在同一個文件中,而是在我的自定義視圖控制器的.m中。 @Noah不起作用,仍然會收到警告。 – Blisra 2011-06-15 22:21:40

+0

編輯:你說得對,諾亞,謝謝! – Blisra 2011-06-15 23:51:40

相關問題