2011-06-15 76 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

相关问题