没有取消分配带有inputAccessoryView的UIViewController [英] UIViewController with inputAccessoryView is not deallocated

查看:134
本文介绍了没有取消分配带有inputAccessoryView的UIViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have simple subclass of UIViewController (code below). If I attach inputAccessoryView, my viewcontroller is never deallocated. If I do not set inputAccessoryView in viewDidLoad, dealloc is called as expected.

我错过了什么吗?

@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

我的想法用完了。
谢谢。

I have ran out of ideas. Thank you.

推荐答案

不幸的是,@ rdelmar的回答没有用。花了一些时间试图解决它后,我找到了这篇文章: http://derpturkey.com/uitextfield-docked-喜欢ios-messenger /

Unfortunately for me @rdelmar's answer didn't work. After some time spent trying to solve it I found this article: http://derpturkey.com/uitextfield-docked-like-ios-messenger/

我的目标是即使键盘没有,也可以看到输入配件视图,就像在所有IM应用中一样。我之前已经将 UIViewController 自定义类子类化,以允许它成为第一响应者,并将我的自定义子视图作为 inputAccessoryView 返回。这阻止了视图控制器被释放。现在我将控制器的视图子类化,以实现与上面链接中建议相同的内容,一切似乎都正常。

My goal is to have the input accessory view visible even if the keyboard is not, exactly like in all IM apps. I previously subclassed my UIViewController custom class to allow it to become first responder and returned my custom subview as inputAccessoryView. This was preventing the view controller from being dealloced. Now I subclass the controller's view to achieve the same thing as recommended in the link above, everything seems to work fine.

编辑:经过一些更多的测试我可以确认自定义UIView被释放得很好。

after some more testing I can confirm the custom UIView is dealloced just fine.

编辑2:唯一的缺点是你不能让键盘出现在 viewWillAppear inputAccessoryView 尚未添加到视图层次结构中,无法成为第一响应者。

EDIT 2: only downside is that you can't make the keyboard appear in viewWillAppear, the inputAccessoryView is not already added to the view hierarchy and can't become first responder.

这篇关于没有取消分配带有inputAccessoryView的UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆