我正在创建一个iPad应用。在其中,我有一个UITabBarController设置,显示3个视图。查看1,视图2和视图3.这一切都很好。在视图1上,用户正在创建订单。然后他们会触摸一个构建订单的按钮。这在模式视图中显示,允许用户在实际发送之前查看它。他们可以“提交”或“编辑”订单,无论哪种方式,我解雇模式并返回到视图1.这也很好。但是如果用户再次触摸“make”命令按钮,则此时加载模态视图会导致崩溃“EXC_BAD_ACCESS”。我复制的代码与我在应用程序中为另一个模态视图所做的一样,没有问题一次又一次显示自己。我在这一点上非常困惑,并感谢任何帮助。谢谢。调用模态的代码是:
-(IBAction) makeOrder {
NSMutableArray *orderItems = [[NSMutableArray alloc] init];
//code that populates orderItems array - removed for brevity
NSLog(@"order items count:%d", [orderItems count]);
// Create the modal view controller
PartsOrderViewController *modalController = [[PartsOrderViewController alloc] initWithNibName:@"PartsOrderView" bundle:nil];
//this is the only difference b/w this and the other modal view. The other
//modal presents as a formsheet
modalController.modalPresentationStyle = UIModalPresentationFullScreen;
modalController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
modalController.orderList = orderItems;
modalController.storeId = selectedCustomer.storeID;
modalController.customerInfo = customerInfo.text;
modalController.customerTamsId = selectedCustomer.customerTAMSID;
// show the Controller modally -- This is the line that cause the error after the second time
[self presentModalViewController:modalController animated:YES];
// Clean up resources
[modalController release];
}
它实际上进入了模态的viewDidLoad,但是一旦完成运行就会崩溃。
以下是模态的代码:
#import "PartsOrderViewController.h"
@implementation PartsOrderViewController
@synthesize customerTamsId;
@synthesize customerInfo;
@synthesize invoiceDate;
@synthesize invoiceTime;
@synthesize storeId;
@synthesize customerInfoLabel;
@synthesize invoiceDateLabel;
@synthesize invoiceTimeLabel;
@synthesize storeIdLabel;
@synthesize orderList;
@synthesize delegate;
#pragma mark -
#pragma mark View methods
-(IBAction) editOrder {
[self dismissModalViewControllerAnimated:YES];
}
-(IBAction) submitOrder {
//code removed for brevity
}
#pragma mark -
#pragma mark View implementation methods
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
}
return self;
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.customerInfoLabel.text = self.customerInfo;
self.storeIdLabel.text = self.storeId;
self.invoiceDateLabel.text = self.invoiceDate;
self.invoiceTimeLabel.text = self.invoiceTime;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return NO;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
更新:找到解决方案:违规代码标记为 -
-(NSMutableArray *)buildOrderList {
NSMutableArray *orderItems = [[NSMutableArray alloc] init];
id cellObject = NULL;
int counter = 0;
NSEnumerator *theEnum = [self.partsList objectEnumerator];
while((cellObject = [theEnum nextObject]) != NULL)
{
GridTableCell *cell = (GridTableCell *)[self.partsListGrid cellForRowAtIndexPath:[NSIndexPath indexPathForRow:counter inSection:0]];
UILabel *lineAbbrev = (UILabel *)[cell.contentView.subviews objectAtIndex:0];
UILabel *partNo = (UILabel *)[cell.contentView.subviews objectAtIndex:1];
UITextView *orderQty = (UITextView *)[cell.contentView.subviews objectAtIndex:3];
//NSLog(@"OrderQty length: %d", [orderQty.text length]);
//NSLog(@"Part#:%@, OrderQty:%@", partNo.text, orderQty.text);
PartOrderIn *invItem = [[PartOrderIn alloc] init];
invItem.lineAbbrev = lineAbbrev.text;
invItem.partNumber = partNo.text;
invItem.orderQty = orderQty.text;
invItem.partMessage = @"";
if ([invItem.orderQty length] > 0) {
[orderItems addObject:invItem];
}
counter++;
[invItem release];
//The following three lines is what was killing it
//[lineAbbrev release];
//[partNo release];
//[orderQty release];
}
//NSLog(@"order items count:%d", [orderItems count]);
return orderItems;
}
答案 0 :(得分:1)
冒着陈述明显的风险(抱歉;)你是通过调试器进行的吗?糟糕的访问可能是一个内存分配问题(再次,显而易见)。如何定义属性(orderList是否保留?其他属性?)。检查崩溃的位置,并在调试器中使用表达式或通过内存地址记下属性的值。我的猜测是你保留的东西没有被保留。
答案 1 :(得分:0)
没有立即跳出来(问题很可能出在简短的代码中),但是你试图启用僵尸吗? How to enable zombies.这通常会给你一些关于罪犯的迹象,或者至少会给你一些关于在哪里看的内容......