UITableViewCell部分重复

问题描述:

我有一个自定义单元格。它有两个文本字段和按钮,所有这些都是我在故事板中创建的。但是当我滚动我的下一个单元格出现与新的文字,但与旧按钮(从第一个单元格按钮)。UITableViewCell部分重复

LessonCell *cell = (LessonCell *)[self.lessonTV dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
     cell = [[LessonCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 

但在我的情况下,这是不够的,它不工作,我的细胞重复,当我滚动,你可以帮我:

据很多教程这种重复的细胞必须在使用该行固定?

还有一点:重复只有第一个单元格((

+0

显示你的整个'cellForRowAtIndexPath'方法。 – rmaddy

+0

@rmaddy它是巨大的,有很多的逻辑,我把它放在这里 - http://codeshare.io/2Ywd9 –

+0

大部分的逻辑应该在你的自定义单元类的代码。 – rmaddy

如果你有一个自定义的类来表示的细胞,您可以覆盖-[UITableViewCell prepareForReuse]方法以重置出现的单元格。

一个侧面说明:

[tableView dequeueReusableCellWithIdentifier:] 

你应该使用

[tableView dequeueReusableCellWithIdentifier:forIndexPath:] 

后者不会被弃用,则不应使用,并且它有一些运行时检查,这将帮助你。

当你第一次创建单元格,将一些值初始化所以,当你向下滚动,将出队的老小区了,既然你。不修改它,老一套的内容将被显示。你可以有一个updateCell方法,每次加载细胞更新UI元素和内容。

LessonCell *cell = (LessonCell *)[self.lessonTV dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) 
    cell = [[LessonCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
[self updateCell]; 


-(void)updateCell{ 
    //do all content and ui updations here 
}