Question

Am I the only one who get this problem?

I have few sections and few rows in grouped table view, for registration page. When I slide up and down the page, there's strange separator bold line appear between two cells. Some of the cell sinks like it has been pressed. Is this a iOS 5.0 bug? I have worked for 3 days for this little problem. Please help!

I have try

self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;

and

self.tableView.separatorColor = [UIColor lightGrayColor];

None of them work.

[Edited]

Paul Peelen you're right and I know what you meant, but I don't have the knowledge to continue forward. Before I comment the "if(cell == nil)", everything is the same as what you've said. But after I comment it, the label is displayed well and no problem with the separator line anymore, but when I insert the texts into the textField and slide down, and up again, the textField's text is gone and been refreshed. How do I solve this one? Below is my code:

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

}

Was it helpful?

Solution 3

OK, this is mainly because the cell identifier. Since the table view recycle its contents to display every time I scroll up and down, and if I use the same cell identifier, strange behaviour like I mentioned above will happen.

This is my solution to all the strange things happen on displaying the table view:

- (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...
}

OTHER TIPS

Do you want a separator colour at all? You could always set it to clear if not.

self.tableView.separatorColor = [UIColor clearColor];

That is most likely due to that you are using different settings on your cells. Since cells are reused and not created as new ones for each cell, you can get a reused cell with different settings on them which have been set by the last cell whom used it.

So for instance, lets say 4 cells are visible in your UITableView. That means that either 6 or 7 are loaded in the memory but not yet visible. Lets say you have a list of 10 cells total, then when you scroll down, cell #8 will only be loaded into the memory when it should be shown, releasing any other cells that should not be shown anymore. So cell #8 will get the former cell #0's cell. If you then set in #8 that the background color should be red, and you scroll up again, you will see that cell #0 will also have a red background, unless you tell cell #0 to have a white background, then it will be white.
The same goes for seperators ect.

Simple way to test this is to make you "cellIdentifier" unique.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top