I’m ussing Xcode 4.4.1 with ARC enabled and storyboards (in case this make a difference)
I have a UITableViewController with a Table View in it (The table view use “subtitle” cells)
I’m using an NSArray to fill my table :
@property (strong, nonatomic) NSArray *myData;
I get the data in this table in viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
self.myData = [self.myCalendarModel GetWeightHistory] ;
}
Then I have : numberOfSectionsInTableView and numberOfRowsInSection
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.myData count];
}
And finally my cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"WeighDataCell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
WeightHistory *myDataForCell = [self.myData objectAtIndex:indexPath.row];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd.MM.YYYY"];
NSString *dateString = [dateFormat stringFromDate:myDataForCell.weightDate];
cell.textLabel.text = dateString;
cell.detailTextLabel.text = [myDataForCell.weight description];
return cell;
}
I can display my table without any problems. I Have the space to display 6 cells and my NSArray have 6 records. When I scroll down on my table, I have no problems.
When I scroll up, I have no problems if no cell get out of the view. As soon as one cell is out of the view when I release my finger I get an Exc_bad_access error.
When debuggin with NSZombieEnable I can see this :
[CalendarHistoryTableViewController tableView:cellForRowAtIndexPath:]: message sent to deallocated instance 0x6eaf6f0
So I guess My cell get released and that’s why I get this issue. But I don’t know when and how to prevent this situation.
Thanks for any help you can provide !
Eric
@FaddishWorm Yes the identifier is set and if cell is not nil that mean it’s allocated. But this part seems to be working because I can get my data up to screen.
@Pandey_Laxman thanks for your comment. That’s allmost the only code I have inside this class. To check is the issue was not related to my WeightHistory object I’have removed this part from the code but I’m still getting the same error
This is how my new cellForRowAtIndexPath looks like :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"WeighDataCell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.textLabel.text = @"test";
cell.detailTextLabel.text = @"test2";
return cell;
}
I figured it out.
My
TableViewControllerwas being displayed on the screen by a segue in anotherViewControllerand I was not storing the currentTableViewControllerpointer in a `strong property.So when iOS tried to call
cellForRowAtIndexPathon myTableViewControllerit wasn’t able to because it had already been released.Thanks for your help guys.
Regards, Eric