2011-01-20 90 views
1

我正在创建一个iPad应用程序。其中,我有一个UITabBarController设置,显示3个视图。查看1,查看2和查看3.这一切都很好。在视图1上,用户正在创建订单。然后他们触摸一个建立订单的按钮。这显示在一个模式视图中,允许用户在实际发送之前查看它。他们既可以“提交”也可以“编辑”订单,无论采用哪种方式,我都会解除模式并返回到视图1.这也可以正常工作。但是,如果用户再次触摸“make”订单按钮,这次模态视图的加载会导致崩溃“EXC_BAD_ACCESS”。我复制代码的方式与我在应用程序中为另一个模式视图所做的相同,但这种方式不会一次又一次地显示出来。我很困惑在这一点上,并会感谢任何帮助。谢谢。调用模式的代码是:调用presentModalViewController导致“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 

UPDATE:发现的解决方案:有问题的代码标记为such-

-(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; 
} 

回答

1

在说明显而易见(对不起)的风险你是否通过调试器步骤?访问不良可能是一个内存分配问题(再次,最明显的)。如何定义属性(是否保留orderList?其他属性?)。检查崩溃的位置并记下属性的值,可以使用调试器中的表达式或内存地址。我的猜测是没有保留,你认为是保留。

0

没有立即跳出(问题比可能在更你为了简洁而删除的代码),但是你是否尝试过启用僵尸? How to enable zombies.这通常会给你一些罪犯的迹象或至少给你一个暗示的地方暗示...

+0

谢谢,我这样做,这是我得到的: - [CALayer layerDidBecomeVisible:]:发送到释放实例的消息0x61683b0 但这对我意味着什么?对不起,我是一个noob。新转换的.NET程序员,我习惯于在出现异常时看到整个堆栈跟踪。 XCode中可能吗?顺便说一句,如果它有帮助,单步执行代码,它会在执行模态视图的viewDidLoad后发生。 – Shaggy13spe 2011-01-22 02:57:39

+0

好吧,这里有一个更奇怪的东西......而不是显示模式视图(仅用于测试),视图1现在显示一个UIAlertView。它会显示成功,两次,但第三次后,kaboom! – Shaggy13spe 2011-01-22 03:00:13

相关问题