繁体   English   中英

调用presentModalViewController会导致“ EXC_BAD_ACCESS”

[英]calling presentModalViewController causes “EXC_BAD_ACCESS”

我正在创建一个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;
}

冒着陈述明显的(抱歉;)的风险,您是否已通过调试器逐步执行此操作? 错误的访问可能是内存分配问题(再次,很明显,先生)。 如何定义属性(是否保留orderList?其他属性?)。 使用调试器中的表达式或按内存地址检查崩溃的位置并记下属性值。 我的猜测是您假设保留了某些未保留的东西。

没有什么立即跳出来的(问题很可能是为简洁起见而删除的代码),但是您是否尝试启用僵尸程序? 如何启用僵尸。 这通常会给您一些有关犯罪者的提示,或者至少会给您一些提示。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM