DEBUG时候发现调用show之后立即调用了release,提示窗口还在显示,按钮还能响应,怎么回事呢?
show竟然不是堵塞的!!!什么原理
UIAlertView *promptWindow = [[UIAlertView alloc]initWithTitle:
@"XXX。"
message:nil
delegate:self
cancelButtonTitle:@"去设置"
otherButtonTitles:@"知道了",
nil];
promptWindow.restorationIdentifier = @"not_first_open";
[promptWindow show];
[promptWindow release];
------解决方案--------------------
是的,init了之后需要release,但是这view依然处于显示状态,那就明它有引用计数此时依然处于非0状态。只有当这个view没有显示了才会被系统销毁。
其实,addSubview,中的参数中的引用计数会+1, removeFromSuperView,引用计数会-1。
另外,数组的addObject也会使对象的引用计数+1。
通常所说的,retain release是指显示的调用,其实在系统内部机制中,有许多需要注意的地方。
这些只有慢慢在开发中理解,并就用自如。