Objective c 调用presentModalViewController会导致“;EXC#u坏访问”;
我正在创建一个iPad应用程序。在它里面,我有一个显示3个视图的UITabBarController设置。视图1、视图2和视图3。这一切都很好。在视图1上,用户正在创建订单。他们制作并点击一个按钮来建立订单。这在模式视图中显示,允许用户在实际发送之前查看它。他们可以“提交”或“编辑”订单,无论哪种方式,我都会取消模式并返回视图1。那也行。但是,如果用户再次触摸“make”order按钮,这一次加载模式视图会导致崩溃“EXC_BAD_ACCESS”。我复制了代码,就像我在应用程序中的另一个模态视图中所做的一样,它可以一次又一次地显示自己。在这一点上我很困惑,希望能得到任何帮助。谢谢调用模态的代码是:Objective c 调用presentModalViewController会导致“;EXC#u坏访问”;,objective-c,ipad,ios,exc-bad-access,modalviewcontroller,Objective C,Ipad,Ios,Exc Bad Access,Modalviewcontroller,我正在创建一个iPad应用程序。在它里面,我有一个显示3个视图的UITabBarController设置。视图1、视图2和视图3。这一切都很好。在视图1上,用户正在创建订单。他们制作并点击一个按钮来建立订单。这在模式视图中显示,允许用户在实际发送之前查看它。他们可以“提交”或“编辑”订单,无论哪种方式,我都会取消模式并返回视图1。那也行。但是,如果用户再次触摸“make”order按钮,这一次加载模式视图会导致崩溃“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;
}
没有任何东西会立即跳出(为了简洁起见,您删除的代码中很可能存在问题),但您是否尝试过启用僵尸?这通常会给你一些罪犯的指示,或者至少给你一个去哪里找的提示…没有任何东西会立即跳出(为了简洁起见,你删除的代码中很可能存在问题),但是你是否尝试过启用僵尸?这通常会给你一些罪犯的指示,或者至少给你一个去哪里找的提示…冒着陈述显而易见的风险(对不起;)你是通过调试器来完成的吗?糟糕的访问可能是一个内存分配问题(同样,mr。如何定义属性(是否保留订单列表?其他属性?)。使用调试器中的表达式或内存地址,检查where is崩溃并记录属性值。我猜有些东西没有被保留,而您认为它被保留了。冒着声明显而易见的风险(抱歉;)您是否通过了调试器?糟糕的访问可能是一个内存分配问题(同样,mr。如何定义属性(是否保留订单列表?其他属性?)。使用调试器中的表达式或内存地址,检查where is崩溃并记录属性值。我猜有些东西没有被保留,而您认为它被保留了。谢谢,我这样做了,下面是我得到的:-[CALayer LayerDibEcomeVisible:]:消息已发送到已解除分配的实例0x61683b0,但这对我意味着什么?对不起,我是个笨蛋。新转换的.NET程序员,我习惯于在异常发生时看到整个堆栈跟踪。这在XCode中可能吗?顺便说一句,如果有帮助的话,单步执行代码,在执行模态视图的viewDidLoad后,它会崩溃。好的,这里有一个更奇怪的事情…视图1现在显示的不是模态视图(只是为了测试),而是UIAlertView。它将成功展示两次,但第三次之后,卡布姆!果不其然,这是一种记忆。我来自c#&VB背景,还没有完全掌握在iOS中处理内存的方法。令人不快的代码是我为了简洁而省略的代码,我甚至不认为它可能发生在那里。嗯,是的我正在用发生错误的代码更新我的原始帖子。谢谢你的帮助,也谢谢你关于僵尸的提示,我从没听说过。谢谢,我这么做了,下面是我得到的:-[CALayer LayerDibEcomeVisible:]:消息发送到了deallocated实例0x61683b0,但这对我意味着什么?对不起,我是个笨蛋。新转换的.NET程序员,我习惯于在异常发生时看到整个堆栈跟踪。这在XCode中可能吗?顺便说一句,如果有帮助的话,单步执行代码,在执行模态视图的viewDidLoad后,它会崩溃。好的,这里有一个更奇怪的事情…视图1现在显示的不是模态视图(只是为了测试),而是UIAlertView。它将成功展示两次,但第三次之后,卡布姆!果不其然,这是一种记忆。我来自c#&VB背景,还没有完全掌握在iOS中处理内存的方法。令人不快的代码是我为了简洁而省略的代码,我甚至不认为它可能发生在那里。嗯,是的我正在用发生错误的代码更新我的原始帖子。谢谢你的帮助,也谢谢你给我的关于僵尸的提示,我从来没听说过。当然,这是一个记忆的东西。我来自c#&VB背景,还没有完全掌握在iOS中处理内存的方法。令人不快的代码是我为了简洁而省略的代码,我甚至不认为它可能发生在那里。嗯,是的我正在用发生错误的代码更新我的原始帖子。谢谢你的帮助的确,这是一件令人难忘的事。我来自c#&VB背景,还没有完全掌握在iOS中处理内存的方法。令人不快的代码是我为了简洁而省略的代码,我甚至不认为它可能发生在那里。嗯,是的我正在用发生错误的代码更新我的原始帖子。谢谢你的帮助