【发布时间】:2014-08-27 01:49:26
【问题描述】:
我有 UIViewController 的简单子类(代码如下)。 如果我附加 inputAccessoryView,我的视图控制器永远不会被释放。如果我没有在 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
我的想法已经用完了。 谢谢。
【问题讨论】:
-
你想把这个 inputAccessoryView 添加到出现的键盘上吗?如果是这样,你做错了。 inputAccessoryView 是 UITextField 上的属性,而不是 UIViewController。我不确定,为什么这样做会导致您的控制器不会被释放,但是如果您将名称更改为 inputAccessoryView 以外的名称,它会被正确释放。因此,似乎错误地使用此属性名称会以某种方式混淆系统。
-
请添加用于设置
self.messageInputView的代码和用于呈现IMTestViewController的代码 -
@rdelmar,inputAccessoryView 是 UIResponder 的一个属性,它是 UIViewController 的超类。
-
@Rafeek,这就是我拥有的所有代码。我为此创建了一个示例项目。 appDelegate 中的代码: UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[UIViewController new]]; [导航 pushViewController:[IMChatIAVViewController new] 动画:NO]; self.window.rootViewController = 导航;
-
我和你的情况相同。如果您找到了解决方案,请告诉我。
标签: ios objective-c ios7 uiviewcontroller uiresponder