【发布时间】:2015-02-25 15:42:30
【问题描述】:
我定义了一个名为 SearchView 的自定义类,它有一个名为“setup”的方法。
// SearchView.h
@interface SearchView:UIView
- (void)setup;
@end
我已将其作为子视图添加到 InterfaceBuilder 中的 MainViewController 中,并将其在身份检查器中的自定义类字段设置为 SearchView 类。我已将它连接到 MainViewController:
// MainViewController.h
@interface MainViewController:UIViewController
@end
// MainViewController.m
#import "SearchView.h"
@interface MainViewController()
@property (nonatomic,strong) IBOutlet SearchView * searchView;
@end
@implementation MainViewController
- (void)ViewDidLoad
{
[self.searchView setup];
}
这个应用程序是通用的,所以我有 2 个故事板。当我在 iPad 模拟器上运行它时,它适用于所有 iOS 版本。但是当我在 iPhone 模拟器上运行它时,它在 iOS 8.1 上运行完美,但在 7.1 上我得到一个不会导致应用程序崩溃的错误。
-[UIView setup]: unrecognized selector sent to instance 0x78882660
我尝试将其移至 ViewDidAppear - 没有变化。 我记录了这个 ivar 的课程
- (void)ViewDidLoad
{
NSLog(@"searchClass class: %@",NSStringFromClass([self.searchView class]));
[self.searchView setup];
}
似乎在 sim' 7.1 上运行时会记录
self.searchView: <UIView: 0x7916f540; frame = (50 0; 234 50); autoresize = RM+BM; layer = <CALayer: 0x7916e360>>
但是在 8.1 sim' 我得到了
self.searchView: <SearchView: 0x79e35170; frame = (50 0; 234 50); autoresize = RM+BM; tag = 4444; layer = <CALayer: 0x79e349b0>>
我尝试标记视图,然后调用它:
self.searchView = (SearchView*)[self.view viewWithTag:4444];
但错误仍然存在。
此外,-ObjC 已添加到其他链接器标志中。
此错误的根源可能是什么?为什么这个视图只针对这个特定的模拟器被转换为 UIView? 我没有任何可用的 iOS 7 iPhone 设备来测试它。
【问题讨论】:
-
你说是在InterfaceBuilder中添加的,为什么属性没有IBOutlet?
-
复制不正确,我已经编辑过了。
-
我没有答案,但“演员”与问题无关。您的日志行表明在这两种情况下它确实是一种不同的视图对象。
OPSearchView的父类是什么(与SearchView有什么不同)? -
这是一个错字,我试图简化给定的代码以便于阅读,但忘记将 OP 从 OPSearchView 中删除。将此视为 SearchView,我深表歉意。已编辑。
-
我也不知道。也许你隐藏了一些重要的东西。
标签: ios iphone xcode6 ios-simulator unrecognized-selector