English 中文(简体)
当释放UIView 对象时,我的应用程序崩溃了
原标题:While releasing the UIView Object my app is crashing

我开发了一个没有 XIB 文件的 iPhone 工程。 我手动创建了 UIView 对象, 以及该视图上的另外几个组件。 我将这些对象放入我的 < code> dealloc 和 < code> ViewAidunload 方法中。 我的问题是, 如果我放出 UIView, 程序会崩溃, 我不知道为什么。 有人能帮我吗?

这是我的代码:

allmessengersview = [[UIView alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; 
allmessengersview.backgroundColor = [UIColor whiteColor];
self.view = allmessengersview;

-(void) dealloc { 
    [allmessengersview release]; 
    [super dealloc]; 
} 

- (void) viewDidUnload { 
    [super viewDidUnload];
    [allmessengersview release]; 
    allmessengersview = nil;
 }
问题回答

请在视图中初始化时写入此代码

allmessengersview=[[UIView alloc]init];
allmessengersview.frame = CGRect (0,0,320,480);
allmessengersview.backgroundColor = [UIColor whiteColor]; 
[self.view addsubView: allmessengersview];

请在交易方法中写下此代码

-(void)dealloc 
{
    [allmessengersview release]; 
    [super dealloc];
}

Don t release in viewDidUnload. This way the app will release allmessengersview in the viewDidUnload and later on it tries to release it a second time in dealloc, but since it s already released, the app crashes.





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签