使用pushviewcontroller后,TableView不滚动

问题描述:

我有tabbarcontroller应用程序。在第一个标签本身,我有桌面视图。我没有添加任何内容到NIB文件。我刚刚创建了UITableViewController的子类。我的细胞是自定义的。它确实显示了具有适当值的表格。使用pushviewcontroller后,TableView不滚动

但是在didSelectRow:方法中,我叫pushViewController。一旦我从pushViewController中按下回到原始屏幕并开始滚动,我的应用程序就会终止。

任何人都可以帮我解决这个问题吗?

//代码

-(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 release]; 

} 


- (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]; 

} 

谢谢

安基塔

+0

一些代码真的会有所帮助。如果你不介意。 – visakh7 2011-03-16 07:05:13

+0

你可以请张贴堆栈跟踪? – hennes 2011-03-16 07:12:41

+0

你们有谁能解决这个问题? – Anks 2011-03-16 08:36:40

没有看到我敢打赌,这是你的选择小区的双重释放的堆栈跟踪。你从的tableView这样获取它

CustomCell *testcell = [tableView cellForRowAtIndexPath:indexPath]; 

,而不是将其保留,然后在方法结束时,你将要发布一个对象,你并不拥有

[testcell release]; 

那么您什么时候返回并开始滚动,tableView可能会尝试释放单元崩溃,因为双释放。只是不要释放你不拥有的东西(创建,分配,复制,保留)。

+0

完美。它通过任何方式解决了错误。我给了不同的标识符,然后它也起作用,甚至通过它的工作方法。非常感谢:) – Anks 2011-03-16 11:01:42

+0

表格视图中的单元格标识符和出列是为了避免为同一类重新分配内存。例如通过出队,您将获得已经设置的CustomCell,然后您必须根据新行设置其属性。不同的标识符应该用于不同的单元类。 – tsakoyan 2011-03-16 13:56:41

问题解决了。我只需要为每个单元格给出不同的CellIdentifier。所以我将代码更改为

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

其中,i是变量声明在头文件中,赋值为零。