hyb*_*ttt 8 objective-c uiviewcontroller uiresponder ios ios7
我有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
Run Code Online (Sandbox Code Playgroud)
我已经没想完了.谢谢.
对我来说很遗憾@ rdelmar的回答没有用.花了一些时间试图解决它后,我找到了这篇文章:http://derpturkey.com/uitextfield-docked-like-ios-messenger/
我的目标是即使键盘没有,也可以看到输入附件视图,就像在所有IM应用程序中一样.我之前将UIViewController自定义类子类化为允许它成为第一响应者并返回我的自定义子视图inputAccessoryView.这阻止了视图控制器被释放.现在我将控制器的视图子类化,以实现与上面链接中建议的相同,一切似乎都正常.
编辑:经过一些更多的测试,我可以确认自定义UIView被解除分配.
编辑2:唯一的缺点是你不能使键盘出现viewWillAppear,inputAccessoryView它还没有添加到视图层次结构中,也不能成为第一响应者.
| 归档时间: |
|
| 查看次数: |
2891 次 |
| 最近记录: |