2011-01-20 102 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