I build a TableView with custom TableViewCell, the first custom cell have a tool bar and some Bar button Item and also a simple button for test.
The problem is : When I click in any bar button item or into simple button I have a EXC_BAD _ACCESS ?
This is my code to build the tableview cells :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"taskCell";
if(indexPath.row != 0){
TaskCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"TaskCell" owner:nil options:nil];
for (UIView *view in views) {
if([view isKindOfClass:[UITableViewCell class]])
{
cell = (TaskCell*)view;
}
}
}
return cell;
}
else{
if (travelInfoCell == nil) {
NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"TravelInfo" owner:nil options:nil];
for (UIView *view in views) {
if([view isKindOfClass:[UITableViewCell class]])
{
travelInfoCell = (TravelInfo*)view;
}
}
}
travelInfoCell.selectionStyle = UITableViewCellSelectionStyleNone;
return travelInfoCell;
}
}
I planed to delegate the action code to the TableViewController, but for the instant I can not even hit the breakpoint in front of the button IBAction.
Code into the TravelInfo.m and is not working and throw to me EXC_BAD _ACCESS :
- (IBAction)doAccepted:(id)sender {
NSLog(@"accepted");
//[delegate travelAccepted];
}
Do have any solution ?
Here’s your problem:
You are not keeping a reference to the view, so there is an implicit limited life expectancy to the view variable. You’ll need to retain to keep a reference. Do this:
Don’t forget to release the cell and nil it out on viewDidUnload