【问题标题】:UIButton deallocated issueUIButton 释放问题
【发布时间】:2011-04-08 12:37:45
【问题描述】:

我从调试器控制台收到了这条消息:

-[UIButton release]:消息发送到释放的实例0x1836b0

但我没有以编程方式创建 UIButton,我所有的按钮都是在 Interface Builder 中创建的。它们中的每一个都链接到一个函数,如下所示:

-(IBAction)theFunction:(UIButton *)sender;

在很多这样的函数中,我不使用变量 sender。我什至不尝试释放它。所以我不明白为什么我的应用程序试图释放我的按钮。 我是否在 Interface Builder 中做一些事情来释放或不释放我的 UIButton?是关于我放在 UIButton 中的图片吗?如果我使用变量 (UIButton *)sender,我需要释放它吗? 这个问题困扰着我,因为我的应用程序崩溃了。

编辑:

- (IBAction)showPopoverOverview:(UIButton *)sender {
    TouchPlanePopover *content = [[TouchPlanePopover alloc] init];
    [content setTheAlbum:@"Overview"];

    // Setup the popover for use in the detail view.
    detailViewPopover = [[UIPopoverController alloc] initWithContentViewController:content];
    detailViewPopover.popoverContentSize = CGSizeMake(600., 400.);
    detailViewPopover.delegate = self;  // Set the sender to a UIButton.

    // Present the popover from the button that was tapped in the detail view.
    [detailViewPopover presentPopoverFromRect:sender.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

    // Set the last button tapped to the current button that was tapped.
    lastTappedButton = sender;
    [content release];
}

detailViewPopover 在 .h 中像这样创建:@property (nonatomic, retain) UIPopoverController *detailViewPopover;

感谢您的帮助 如果您需要更多信息,请告诉我,我会编辑帖子

【问题讨论】:

  • 你会合成按钮吗?
  • 我需要合成在 Interface Builder 中创建的按钮?
  • 不,仅当您想向他们发送消息时。
  • 我不想给他们发消息,我只想在按下按钮时启动一个功能。
  • 崩溃发生在哪里?你能发布一个堆栈跟踪吗?

标签: ios memory-management uibutton


【解决方案1】:

改变

-(IBAction)theFunction:(UIButton *)sender

-(IBAction)theFunction:(id)sender 

试试吧……

【讨论】:

  • 在某些功能中,我需要放 UIButton
【解决方案2】:

我正在研究这个并且它的工作正常

所以可能对你有用。

myController.h

#import

@class myController;

@interface myController : UIViewController {

}

- (IBAction)onButtonClick:(UIButton *)button;

@结束

myController.m

@implementation myController

- (IBAction)onButtonClick:(UIButton *)button {

NSLog(@"工作正常");

}

【讨论】:

  • 我的功能有效,当我按下按钮时,它会显示我想要的内容
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多