2012-05-03 111 views
2

我是唯一一个得到这个问题的人吗?iOS Xcode - 分组TableView分隔线显示

我在分组表格视图中有几行和几行,用于注册页面。当我在页面上下滑动时,在两个单元格之间出现奇怪的分隔符粗体线条。一些像它一样的细胞汇已被按下。这是一个iOS 5.0的错误?我为这个小问题工作了3天。请帮忙!

我有尝试

self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;

self.tableView.separatorColor = [UIColor lightGrayColor]; 

他们没有工作。

[编辑]

保罗Peelen你说的没错,我知道你的意思,但我没有知识,继续前进。在我评论“if(cell == nil)”之前,所有内容都与你所说的一样。但是在我发表评论之后,标签显示的很好,并且不再存在分隔线问题,但是当我将文本插入到textField中并向下滑动时,textField的文本消失并被刷新。我该如何解决这个问题? 下面是我的代码:

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

//Here's the problem! 
if(cell == nil) 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

cell.selectionStyle = UITableViewCellSelectionStyleNone; 

UILabel *keyLbl = [[UILabel alloc] initWithFrame:CGRectMake(15, 8, 100, 30)]; 
keyLbl.font = [UIFont fontWithName:@"Futura-CondensedExtraBold" size:15.0]; 
keyLbl.textColor = [UIColor colorWithRed:0.275 green:0.275 blue:0.275 alpha:0.9]; 
keyLbl.backgroundColor = [UIColor clearColor]; 


valTxtField = [[UITextField alloc] initWithFrame:CGRectMake(120, 5, 180, 30)]; 
valTxtField.font = [UIFont fontWithName:@"Futura-CondensedExtraBold" size:18.0]; 
valTxtField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
valTxtField.delegate = self; 
valTxtField.returnKeyType = UIReturnKeyDone; 
valTxtField.autocorrectionType = UITextAutocorrectionTypeNo; 
valTxtField.autocapitalizationType = UITextAutocapitalizationTypeNone; 

if(indexPath.section == 0) 
{ 
    if(indexPath.row == 0) 
    { 
     keyLbl.text = NSLocalizedString(@"REGIS_EMAIL", nil); 
     email_TextField = valTxtField; 
    } 
    else if(indexPath.row == 1) 
    { 
     keyLbl.text = NSLocalizedString(@"REGIS_RE_EMAIL", nil); 
     reEmail_TextField = valTxtField; 
    } 
    else if(indexPath.row == 2) 
    { 
     keyLbl.text = NSLocalizedString(@"REGIS_PWD", nil); 
     password_TextField = valTxtField; 
     valTxtField.secureTextEntry = YES; 
    } 
    else if(indexPath.row == 3) 
    { 
     keyLbl.text = NSLocalizedString(@"REGIS_RE_PWD", nil); 
     rePassword_TextField = valTxtField; 
     valTxtField.secureTextEntry = YES; 
    } 

} 
else if(indexPath.section == 1) 
{ 
    if(indexPath.row == 0) 
    { 
     keyLbl.text = NSLocalizedString(@"REGIS_FIRSTNAME", nil); 
     firstName_TextField = valTxtField; 
    } 
    if(indexPath.row == 1) 
    { 
     keyLbl.text = NSLocalizedString(@"REGIS_LASTNAME", nil); 
     lastName_TextField = valTxtField; 
    } 
    if(indexPath.row == 2) 
    { 
     keyLbl.text = NSLocalizedString(@"REGIS_POSTCODE", nil); 
     postCode_TextField = valTxtField; 
    } 
    if(indexPath.row == 3) 
    { 
     keyLbl.text = NSLocalizedString(@"REGIS_GENDER", nil); 
     gender_TextField = valTxtField; 
    } 
    if(indexPath.row == 4) 
    { 
     keyLbl.text = NSLocalizedString(@"REGIS_DOB", nil); 
     DOB_TextField = valTxtField; 
    } 
    if(indexPath.row == 5) 
    { 
     keyLbl.text = NSLocalizedString(@"REGIS_MOBILE", nil); 
     mobile_TextField = valTxtField; 
    } 
} 
[cell addSubview:keyLbl]; 
[cell addSubview:valTxtField]; 
[keyLbl release]; 
[valTxtField release]; 

return cell; 

}

回答

0

好的,这主要是因为小区标识符。由于表视图循环的内容,以显示我每次上下滚动时间,如果我用同样的小区标识,就像我上面提到的奇怪的行为会发生。

这是我的解决方案给所有的奇怪的事情发生上显示的表视图:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
//Here the solution: 
NSString *CellIdentifier = [NSString stringWithFormat:@"RCell%1dR%1d",indexPath.section,indexPath.row]; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) 
{ 
    //your tableView code... 
} 
1

你想一个分离器的颜色呢?如果没有,你可以随时设置它。

self.tableView.separatorColor = [UIColor clearColor]; 
+0

号我刚刚发布我的代码。你可以看看上面。 – felixwcf

1

这是最可能的原因是你在你的细胞中使用不同的设置。由于细胞被再利用,而不是对每个小区新创建的,你可以用在已经设定由谁来用它的最后一个单元格对他们不同的设置重用细胞。

因此,举个例子,假设4个单元格在UITableView中可见。这意味着要么6或7被加载到内存中,但尚未可见。比方说你有10个小区的名单总,然后当你向下滚动,小区#8只被加载到内存时,应当显示,释放不应该再表现出任何其他细胞。所以8号单元会得到前一个单元#0的单元。如果您在#8中设置背景颜色应该是红色,并且再次向上滚动,则会看到#0单元格也会具有红色背景,除非您告诉单元格#0具有白色背景,否则它会变白。
分离器等也是如此。

简单的方法来测试这是让你“cellIdentifier”唯一。