我有一个非常奇怪的问题,我想我知道我为什么会得到它,但我似乎想不出解决办法。我确信这里没有编译器错误。由于我的代码错误,我遇到过很多这样的情况,所有这些都发生了。
基本上,我有一个从 UIViewController 继承的名为 UnlockKeyboardViewController 的视图控制器,以及一个名为 UnlockKeyboard 的自定义视图(直接从 UIView 继承)。UnlockKeyboard 的标题如下所示:
@interface UnlockKeyboard : UIView
{
NSArray *buttons;
NSArray *passcodeFields;
UIImage *buttonBackgroundImage;
UIImage *buttonBackgroundHighlightedImage;
UIImage *middleButtonBackgroundImage;
UIImage *middleButtonBackgroundImageHighlighted;
UIImage *screenBackgroundImage;
UIImage *infoViewContainerImage;
UIImage *keypadViewContainerImage;
UIImage *passcodeFieldsContainerImage;
UIImage *infoViewImage;
UIImage *passcodeViewImage;
UIView *infoViewContainer;
UIView *keypadViewContainer;
UIView *passcodeFieldsContainer;
UIView *infoView;
UIView *keypadView;
UIView *passcodeFieldsView;
UIView *infoToDisplayView; //The view the programmer passes to show in infoView.
}
@property(nonatomic, retain)UIImage *buttonBackgroundImage;
@property(nonatomic, retain)UIImage *buttonBackgroundHighlightedImage;
@property(nonatomic, retain)UIImage *screenBackgroundImage;
@property(nonatomic, retain)UIImage *keypadViewBackgroundImage;
@property(nonatomic, retain)UIImage *infoViewContainerImage;
@property(nonatomic, retain)UIImage *keypadViewContainerImage;
@property(nonatomic, retain)UIImage *passcodeFieldsContainerImage;
@property(nonatomic, retain)UIImage *infoViewImage;
@property(nonatomic, retain)UIImage *passcodeViewImage;
@property(nonatomic, retain)UIView *infoToDisplayView;
//Properties for container views.
@property(nonatomic, retain)UIView *infoViewContainer;
@property(nonatomic, retain)UIView *keypadViewContainer;
@property(nonatomic, retain)UIView *passcodeFieldsContainer;
@end
到目前为止,UnlockKeyboardViewController 实现看起来像这样:
@implementation UnlockKeyboardViewController
-(id)init
{
if((self = [super init]))
{
self.view = [[UnlockKeyboard alloc] init];
}
return self;
}
-(void)viewDidLoad
{
[super viewDidLoad];
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[UIView animateWithDuration:0.7 animations:^{
self.view.keypadViewContainer.frame = CGRectMake(0, 261, 320, 200);
} completion:^(BOOL finished){
}];
}
-(void)dealloc
{
[super dealloc];
}
@end
这是我的问题变得有趣。每当我尝试编译时,终端(这是一个越狱应用程序,所以没有 Xcode)给我以下错误:
In function ‘void __-[UnlockKeyboardViewController viewDidAppear:]_block_invoke_1(void*)’:
Segmentation fault: 11
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://developer.apple.com/bugreporter> for instructions.
但是,此错误仅在我输入此行时出现:
self.view.keypadViewContainer.frame = CGRectMake(0, 261, 320, 200);
如果我的动画块中没有那一行,编译器不会给我那个错误,它会编译得很好。虽然,不管我放这条线,我总是得到分段线 11。
我认为这可能与 UIView 没有名为 keypadViewContainer 的成员这一事实有关,尽管 UnlockKeyboard 具有该属性并且是 UIView 的子类。我相信这是因为编译器实际上无法看到 UIView 和 UnlockKeyboard 之间的类层次结构。
如果我是对的,我不知道如何解决这个问题。想了一会儿。任何帮助我解决这个问题的意见将不胜感激。