带有inputAccessoryView的UIViewController不会被释放

我有简单的UIViewController的子类(下面的代码)。 如果我附上inputAccessoryView,我的viewcontroller永远不会被释放。 如果我不在viewDidLoad中设置inputAccessoryView,则按预期方式调用dealloc。

我错过了什么吗?

@interface IMTestViewController : UIViewController @property (nonatomic, strong) UIView *messageInputView; @property(nonatomic, readwrite, strong) UIView *inputAccessoryView; @end @implementation IMTestViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)dealloc { } - (void)viewDidLoad { [super viewDidLoad]; self.inputAccessoryView = self.messageInputView; } - (BOOL)canBecomeFirstResponder { return YES; } - (UIView *)messageInputView { if (_messageInputView == nil) { _messageInputView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 45)]; _messageInputView.autoresizingMask = UIViewAutoresizingFlexibleWidth; } return _messageInputView; } @end 

我已经跑出了想法。 谢谢。

对我来说不幸的是,@ rdelmar的答案是行不通的。 花了一些时间试图解决它,我发现这篇文章: http : //derpturkey.com/uitextfield-docked-like-ios-messenger/

我的目标是使input附件视图可见,即使键盘不是,就像在所有IM应用程序中一样。 我以前subclassed我的UIViewController自定义类,以使其成为第一响应者,并返回我的自定义子视图为inputAccessoryView 。 这阻止了视图控制器被交易。 现在我inheritance控制器的视图,以达到上面链接build议的相同的东西,一切似乎工作正常。

编辑:经过一些更多的testing,我可以确认自定义UIView交易就好了。

编辑2:唯一的缺点是,你不能让键盘出现在viewWillAppearinputAccessoryView不是已经添加到视图层次结构,不能成为第一响应者。