Iphone 以编程方式添加了使应用程序崩溃的按钮

Iphone 以编程方式添加了使应用程序崩溃的按钮,iphone,objective-c,Iphone,Objective C,当我按下按钮时,应用程序崩溃。即使我以编程方式创建按钮或尝试通过XIB为需要按钮的类添加按钮时,也会发生这种情况 我启用了僵尸,从控制台获得的调试消息是: 2010-10-27 00:47:28.643 CarTrawler[1537:207]*-[ReceiptView性能选择器:withObject:withObject:]:消息发送到解除分配的实例0x76cb700 但是按钮被添加到视图中。所以我不明白问题是什么。该类表示收据,因此根据应用程序中的收据数量调用它 - (void)viewD

当我按下按钮时,应用程序崩溃。即使我以编程方式创建按钮或尝试通过XIB为需要按钮的类添加按钮时,也会发生这种情况

我启用了僵尸,从控制台获得的调试消息是:


2010-10-27 00:47:28.643 CarTrawler[1537:207]*-[ReceiptView性能选择器:withObject:withObject:]:消息发送到解除分配的实例0x76cb700

但是按钮被添加到视图中。所以我不明白问题是什么。该类表示收据,因此根据应用程序中的收据数量调用它

- (void)viewDidLoad {
[super viewDidLoad];
self.refLabel.text = theBooking.confID;
self.carTypeLabel.text = theBooking.vehMakeModelName;
//self.amountLabel.text = [NSString stringWithFormat:@"€22.00"];
self.locationLabel.text = [NSString stringWithFormat:@"%@, %@", 
    theBooking.locationName, theBooking.locationAddress];
self.numberLabel.text = theBooking.locationPhoneNumber;

self.dateTimeLabel.text = theBooking.puDateTime;
self.doDateTimeLabel.text = theBooking.doDateTime;
DLog(@"Dropoff date time label is %@", theBooking.doDateTime);

CTTableViewAsyncImageView *thisImage = [[[CTTableViewAsyncImageView alloc] 
initWithFrame:CGRectMake(0.0, 0.0, 64.0, 40.0)] autorelease];
[vendorImage addSubview:thisImage];
NSURL *url = [NSURL URLWithString:theBooking.vehPictureUrl];
[thisImage loadImageFromURL:url];

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(220, 270, 60, 30);
[button setTitle:@"Email!" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonPressed)   
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];

}


-(void)buttonPressed {
NSLog(@"Button Pressed!");
}

谁能解释一下我忽略了什么?

我想你需要保留你的按钮


您发布此消息已经有一段时间了,您知道了吗?

您确定释放的实例是按钮,而不是buttonPressed方法中的某个内容吗?NSZombie应该返回有问题的对象的类型。您可以发布崩溃日志的其余部分吗?应该不仅仅是向解除分配的实例0x8250730.2010-10-27 00:47:28.643 CarTrawler[1537:207]***-[ReceiptView性能选择器:withObject:withObject:]:向解除分配的实例0x76CB700发送消息,因此它似乎是提前解除分配的ReceiptView实例。一种可能性是:您是否正在执行performSelector:afterDelay:并且视图在启动之前被解除分配?是的,这就是问题所在。