I am getting an EXC_BAD_ACESS when I click on my UITextField that I created programmaticly.In my ViewController I have a button that creates a new UIImageView and adds it as a subView. Since I had off the UITextImages and release the ListItem Object It should become the responsibility of the UIImageView to manage it's memory at this point, right? It crashes as soon as I click in the textField which I assume is caused but an object that is already relased.
Here is the ViewDidLoad in my MoneySheet.m (MoneySheetViewController)
And the code for creating a UITextField that is located in a Class called ListItem.m with a NSObject as it's super class
Why is it being released? I have spent the night trying to figure this out.
Code:
-(IBAction)createSheet:(id) sender{
MoneySheet *newSheet = [[MoneySheet alloc] initWithNibName:@"MoneySheet" bundle:nil];
[self.view addSubview: newSheet.view];
[newSheet release];
}
Code:
- (void)viewDidLoad
{
UIImage * moneySheet = [UIImage imageNamed:@"moneyListSheet.png"]; [COLOR="SeaGreen"]//Create BackGround Image[/COLOR]
UIImageView * moneySheetView =[[UIImageView alloc]initWithImage:moneySheet];
moneySheetView.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:moneySheetView];
UILabel *headerInfoLabel = [[[UILabel alloc ]initWithFrame:CGRectMake(25, 0, 200, 30)]autorelease];[COLOR="SeaGreen"]// add Label[/COLOR]
headerInfoLabel.text = @"Money List";
headerInfoLabel.backgroundColor = [UIColor clearColor];
headerInfoLabel.font = [UIFont fontWithName:@"Marker Felt" size: 22.0];
[self.view addSubview:headerInfoLabel];
UILabel *headerItemList = [[[UILabel alloc ]initWithFrame:CGRectMake(63, 25, 300, 30)]autorelease]; [COLOR="SeaGreen"]//Add Label[/COLOR]
headerItemList.text = @"Items Monthly Total";
headerItemList.backgroundColor = [UIColor clearColor];
headerItemList.font = [UIFont fontWithName:@"Marker Felt" size: 14.0];
headerItemList.font = [UIFont boldSystemFontOfSize:17.0];
[self.view addSubview:headerItemList];
float rowDistance = 55.0;
[COLOR="Red"] for (int i = 0; i < 1; i++) { // for loop to add UITextFields
[COLOR="Blue"]ListItem *row = [[ListItem alloc] init];[/COLOR]
[self.view addSubview:[row makeItem:rowDistance]];
[self.view addSubview:[row makeMonthly:rowDistance]];
[self.view addSubview:[row makeTotal:rowDistance]];
[self.view addSubview:[row makeDollarSigns:rowDistance]];
[self.view addSubview:[row makeDollarSignsTwo:rowDistance]];
rowDistance = rowDistance + 30;;
[COLOR="Blue"][row release];[/COLOR][/COLOR]
}
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
Code:
-(UITextField *)makeItem:(float) rowHeight{
firstOne = [[[UITextField alloc] initWithFrame:CGRectMake(15.0f, rowHeight, 130.f, 25.0f)] autorelease];
firstOne.borderStyle = UITextBorderStyleRoundedRect;
[firstOne setReturnKeyType:UIReturnKeyDefault];
[firstOne setEnablesReturnKeyAutomatically:YES];
[firstOne setDelegate:self];
return firstOne;
}
Why is it being released? I have spent the night trying to figure this out.