Я создаю приложение для iPad. В нем у меня установлен UITabBarController, который показывает 3 вида. View 1, View 2 и View 3. Все это работает отлично. В представлении 1 пользователь создает заказ. Затем они нажимают кнопку, которая строит порядок. Это показано в модальном представлении, которое позволяет пользователю просмотреть его перед его отправкой. Они могут либо «отправить», либо «отредактировать» заказ, в любом случае, я отклоняю модальный и вернусь к представлению 1. Это тоже работает отлично. Но если пользователь снова коснется кнопки «сделать», на этот раз загрузка модального представления вызывает сбой «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: Решение найдено: Оскорбление кода отмечен как Сучковый
-(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;
}
Конечно, это была память. Я исхожу из фона C# и VB и до сих пор не полностью справился с обработкой памяти в iOS. Оскорбительный код был в коде, который я забыл для краткости, не думая, что это возможно даже там. Ну, это было так. :) Я обновляю свой исходный пост с битом кода, где произошла ошибка. Спасибо за вашу помощь – Shaggy13spe