Why tableview works fine on the iOS 6+ simulator, but in iOS 5 simulator it crashes

I am using the code below - UITableViewDataSource . The methods are as follows:

numberOfRowsInSection

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

return [dataArray count];
}

cellForRowAtIndexPath

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

// Configure the cell...
if (cell == nil) {

    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

cell.textLabel.text = dataArray[indexPath.row];

return cell;
}
+3
source share
2 answers
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

But in iOS 5, we usually use this method to create an instance of UITableViewCell: -

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

In iOS 5, there is no need for an additional parameter that you used in iOS 6. Just release it and it will work (forIndexPath :).

+4
source

All Articles