开发者

TableView doesn't scroll after using pushviewcontroller

开发者 https://www.devze.com 2023-02-17 15:28 出处:网络
I have tabbarcontroller application. In which on first tab itself I have table view. I haven\'t added anything to NIB file. I have just created subclass of UITableViewController. My cells are custom.

I have tabbarcontroller application. In which on first tab itself I have table view. I haven't added anything to NIB file. I have just created subclass of UITableViewController. My cells are custom. It does show the table with proper values.

But on didSelectRow: method, I have called pushViewController. Once I press back from pushViewController and come back to original screen and start scrolling, my application terminates.

Can anyone please help me out for this?

//Code

 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

{

static NSString *CellIdentifier = @"Cell";

CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) 

{

cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

}

// Configure the cell...

    NSString *TitleValue = [listOfTitles objectAtIndex:indexPath.row];

    cell.primaryLabel.text = TitleValue;

NSString *DateValue = [listOfDates objectAtIndex:indexPath.row];

    cell.secondaryLabel.text = DateValue;



NSString *descValue=[listOfDesc objectAtIndex:indexPath.row];

cell.thirdlabel.text = descValue;



if([unreadFlag objectAtIndex:indexPath.row]  == @"0")

{

cell.primaryLabel.font = [UIFont boldSystemFontOfSize:15.0];

}

else {

cell.primaryLabel.font = [UIFont systemFontOfSize:15.0];

}


return cell;

//[CustomCell relea开发者_如何学Cse];

}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

return 105;

}


#pragma mark -

#pragma mark Table view delegate


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

CustomCell *testcell = [tableView cellForRowAtIndexPath:indexPath];

testcell.primaryLabel.font = [UIFont systemFontOfSize:15.0];

[unreadFlag replaceObjectAtIndex:indexPath.row withObject:@"1"];

selectedNS = [listOfIds objectAtIndex:indexPath.row];

//Initialize the detail view controller and display it.

DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];

dvController.selectedNS=selectedNS;

[self.navigationController pushViewController:dvController animated:NO];

[dvController release];

dvController = nil;  



testcell.primaryLabel.font = [UIFont systemFontOfSize:15.0];

[testcell release];

}

- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {

//return UITableViewCellAccessoryDetailDisclosureButton;

return UITableViewCellAccessoryDisclosureIndicator;

}


- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {

[self tableView:tableView didSelectRowAtIndexPath:indexPath];

}

Thank you,

Ankita


Without seeing the stacktrace I bet it's a double release of your selected cell. You're fetching it from the tableView this way

CustomCell *testcell = [tableView cellForRowAtIndexPath:indexPath];

and not retaining it, then at the end of the method you're releasing an object you don't own

[testcell release];

Then when you return and start scrolling, the tableView might try to release that cell crashing because of a double release. Just don't release what you don't own (with create, alloc, copy, retain).


Issue is solved. I just need to give different CellIdentifier for each of the cell. So I changed the code to

NSString *CellIdentifier =  [NSString stringWithFormat:@"Cell%d", i]; 

Where i is variable declared in header file with assigned value as zero.

0

精彩评论

暂无评论...
验证码 换一张
取 消