UITableViewCell
滚动时我的位置发生了变化UITableView
。在这里我有更多UITableViewCell
。所以它覆盖了不止一页的屏幕。当我从上到下滚动时,位置UITableViewCell
会发生变化,例如第一个单元格排在第 5 个。第二个细胞来到第一个等等。
我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"SignUpWithEmailCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
switch (indexPath.row) {
case 0: {
UILabel *lblFirstName = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
lblFirstName.text = @"First Name";
[cell.contentView addSubview:lblFirstName];
self.txtFirstName = [[UITextField alloc]initWithFrame:CGRectMake(lblFirstName.frame.origin.x + lblFirstName.frame.size.width + 5, 0, 190, 40)];
self.txtFirstName.delegate = self;
self.txtFirstName.text = strFirstName;
self.txtFirstName.tag = 0;
self.txtFirstName.userInteractionEnabled = YES;
self.txtFirstName.font = [UIFont systemFontOfSize:15.0];
self.txtFirstName.clearButtonMode = UITextFieldViewModeWhileEditing;
self.txtFirstName.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[cell.contentView addSubview:self.txtFirstName];
break;
} case 1: {
UILabel *lblLastName = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
lblLastName.text = @"Last Name";
[cell.contentView addSubview:lblLastName];
self.txtLastName = [[UITextField alloc]initWithFrame:CGRectMake(lblLastName.frame.origin.x + lblLastName.frame.size.width + 5, 0, 190, 40)];
self.txtLastName.backgroundColor = [UIColor clearColor];
self.txtLastName.delegate = self;
self.txtLastName.tag = 1;
self.txtLastName.text = strLastName;
self.txtFirstName.userInteractionEnabled = YES;
self.txtLastName.returnKeyType = UIReturnKeyDone;
self.txtLastName.clearButtonMode = UITextFieldViewModeWhileEditing;
self.txtLastName.font = [UIFont systemFontOfSize:15.0];
self.txtLastName.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[cell.contentView addSubview:self.txtLastName];
break;
}
default:
break;
}
}
return cell;
}
谁能指导我正确存档它..
提前致谢。