【问题标题】:'UITabBarController' may not respond to '-method'“UITabBarController”可能不响应“-method”
【发布时间】:2011-06-16 07:46:09
【问题描述】:

我的设置:主窗口带有一个标签栏控制器(包括一个标签栏)和两个UIViewControllers,它们都分配给扩展UIViewController的同一个接口。这个自定义接口实现了一个IBOutlet Webview 和一个加载 URL 的 void。在主.m 上的didSelectViewController 上,我尝试拨打LoadURL

.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

视图控制器的.h

  #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 
}

我在每个 void 上都设置了断点,然后它们就会被调用。但是我的 webView 没有显示任何内容。

除此之外,我收到了 2 个警告:

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

【问题讨论】:

  • 你是在视图控制器头文件中定义LoadURL方法吗?如果是这样,您如何定义它?
  • 感谢您的回复。我已经编辑了我的帖子以包含 .h 文件。

标签: objective-c ios


【解决方案1】:

如果你确定它不是 UIViewController 而是它的子类,你很可能必须强制转换它

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

【讨论】:

  • 谢谢,是的,我已经想到了。它是 UIViewController 的子类。但我得到:'MyTabBarController' undeclared (first use in this function)
  • 能否请您提示我如何导入它?
  • 在你的文件的开头#import "MyTabBarController.h" 或任何文件被调用,你的类驻留在
  • 谢谢。现在我已经导入了,MyTabBarController 就可以解决了。但我仍然收到警告:'MyTabBarController 可能无法响应'-LoadURL:'
  • 您是否在 MyTabBarController.h 中声明了 -LoadURL:?可以给我们看看文件吗?
【解决方案2】:

您的-LoadURL: 方法未在UITabBarController 上定义。也许你的意思是这样做

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

?

【讨论】:

  • 感谢您的回复。 @Dave我不明白,对不起:自我对我不起作用。也许是因为 -LoadURL 不在同一个文件中,而是在我的自定义视图控制器的 .m 中? @Noah 不起作用,仍然收到警告。
猜你喜欢
  • 1970-01-01
  • 2011-11-02
  • 2011-05-24
  • 2017-01-31
  • 2013-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多