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;
}
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: