使用以下代码时,我遇到了重叠问题。我使用自定义单元格和普通单元格样式。
感谢任何建议
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *RSVNIdentifier = @"RSVNCell";
CreateReservationViewCell *cell = (CreateReservationViewCell *)[tableView dequeueReusableCellWithIdentifier:RSVNIdentifier] ;
if (cell == nil) {
cell = [[[CreateReservationViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:RSVNIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
if(indexPath.section == 0)
{
{
if(indexPath.row == 0){
//cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.editing =NO;
cell.m_rsvn_name.text =@"Customer";
cell.m_rsvn_value.text =[[[create_reservation_detail objectAtIndex:0] objectForKey:@"reservation"] objectForKey:@"createdBy"];
cell.m_rsvn_value.enabled=NO;
return cell;
}
if(indexPath.row == 1){
cell.m_rsvn_name.text =@"Till";
cell.m_rsvn_value.text =[[[create_reservation_detail objectAtIndex:0] objectForKey:@"reservation"] objectForKey:@"createdDate"];
cell.m_rsvn_value.enabled=NO;
return cell;
}
if(indexPath.row == 2){
//cell.selectionStyle = UITableViewCellSelectionStyleNone;
emailTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
emailTextField.adjustsFontSizeToFitWidth = YES;
emailTextField.font = [UIFont systemFontOfSize:12];
emailTextField.textAlignment= UITextAlignmentRight;
emailTextField.keyboardType= UIKeyboardTypeEmailAddress;
emailTextField.returnKeyType = UIReturnKeyDone;
emailTextField.tag=0;
emailTextField.delegate=self;
emailTextField.text =[textFields objectAtIndex:0];
cell.m_rsvn_name.text =@"Email";
[cell addSubview:emailTextField];
return cell;
}
if(indexPath.row == 3){
cell.m_rsvn_name.text =@"Telephone";
phoneTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
phoneTextField.adjustsFontSizeToFitWidth = YES;
phoneTextField.font = [UIFont systemFontOfSize:12];
phoneTextField.textAlignment= UITextAlignmentRight;
phoneTextField.keyboardType= UIKeyboardTypePhonePad;
phoneTextField.delegate=self;
phoneTextField.tag=1;
phoneTextField.text =[textFields objectAtIndex:1];
cell.m_rsvn_name.text =@"Phone";
[cell addSubview:phoneTextField];
return cell;
}
if(indexPath.row == 4){
cell.m_rsvn_name.text =@"Internal Note";
cell.m_rsvn_value.text =[[[create_reservation_detail objectAtIndex:0] objectForKey:@"reservation"] objectForKey:@"internalNote"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.m_rsvn_value.enabled=NO;
return cell;
}
}
}
else if(indexPath.section == 1){
NSLog(@"%@",unit_details);
//[[create_reservation_detail objectAtIndex:0] objectForKey:@"reservation"] objectForKey:@"unitName"];
for (int i=0; i<[unit_details count]; i++) {
if(indexPath.row == i){
cell.m_unit_title.text = [[unit_details objectAtIndex:0] objectForKey:@"unitName"];
cell.m_unit_value1.text = [[unit_details objectAtIndex:0] objectForKey:@"nights"];
cell.m_unit_value2.text =[[unit_details objectAtIndex:0] objectForKey:@"adults"];
return cell;
}
}
}
else if(indexPath.section == 2){
if(indexPath.row == 0){
cell.m_rsvn_name.text = @"Total Charges";
cell.m_rsvn_value.text =[[[create_reservation_detail objectAtIndex:0] objectForKey:@"charges"] objectForKey:@"totalRoomCharge"];
return cell;
}
if(indexPath.row == 1){
cell.m_rsvn_name.text = @"10% Tax";
cell.m_rsvn_value.text =[[[create_reservation_detail objectAtIndex:0] objectForKey:@"charges"] objectForKey:@"roomTaxAmount"];
return cell;
}
if(indexPath.row == 2){
cell.m_rsvn_name.text = @"Total Charges1";
cell.m_rsvn_value.text =[[[create_reservation_detail objectAtIndex:0] objectForKey:@"charges"] objectForKey:@"otherCharge"];
return cell;
}
if(indexPath.row == 3){
cell.m_rsvn_name.text = @"Total Charges2";
cell.m_rsvn_value.text =[[[create_reservation_detail objectAtIndex:0] objectForKey:@"charges"] objectForKey:@"totalCharge"];
return cell;
}
if(indexPath.row == 4){
cell.m_rsvn_name.text = @"Total Payments";
//cell.m_rsvn_value.text =[[[create_reservation_detail objectAtIndex:0] objectForKey:@"charges"] objectForKey:@"totalPayment"];
return cell;
}
if(indexPath.row == 5){
cell.m_rsvn_name.text = @"Current Balance";
cell.m_rsvn_value.text =[[[create_reservation_detail objectAtIndex:0] objectForKey:@"charges"] objectForKey:@"currentBalance"];
return cell;
}
}
else if(indexPath.section == 3){
if(indexPath.row == 0){
cell.m_rsvn_name.text =[[[create_reservation_detail objectAtIndex:0] objectForKey:@"deposit"] objectForKey:@"description"];
cell.m_rsvn_value.text =[[[create_reservation_detail objectAtIndex:0] objectForKey:@"deposit"] objectForKey:@"amount"];
return cell;
}
else if(indexPath.row == 1){
cell.m_rsvn_name.text =@"Amount Due";
cell.m_rsvn_value.text =[[[create_reservation_detail objectAtIndex:0] objectForKey:@"deposit"] objectForKey:@"amount_due"];
return cell;
}
else if(indexPath.row == 2){
cell.m_rsvn_name.text =@"Security Deposit status";
cell.m_rsvn_value.text =[[[create_reservation_detail objectAtIndex:0] objectForKey:@"deposit"] objectForKey:@"securityStatus"];
return cell;
}
else if(indexPath.row == 3){
cell.m_rsvn_name.text =@"Security Deposit Due";
cell.m_rsvn_value.text =[[[create_reservation_detail objectAtIndex:0] objectForKey:@"deposit"] objectForKey:@"securityStatus_due"];
return cell;
}
else if(indexPath.row == 4){
static NSString *SecurityCellIdentifier = @"Cell";
UITableViewCell *security_cell = [tableView dequeueReusableCellWithIdentifier:SecurityCellIdentifier];
if (security_cell == nil) {
security_cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:SecurityCellIdentifier] autorelease];
}
// Configure the cell...
security_cell.textLabel.text = @"Security Deposit Instruction:";
security_cell.textLabel.font = [UIFont systemFontOfSize:14];
security_cell.detailTextLabel.text =[[[create_reservation_detail objectAtIndex:0] objectForKey:@"deposit"] objectForKey:@"instruction"];
security_cell.textLabel.font = [UIFont systemFontOfSize:14];
security_cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
security_cell.detailTextLabel.numberOfLines = 0;
[security_cell.detailTextLabel sizeToFit];
return security_cell;
}
}
else if(indexPath.section == 4){
static NSString *Payment_CellIdentifier = @"Payment_Cell";
UITableViewCell *pay_cell = [tableView dequeueReusableCellWithIdentifier:Payment_CellIdentifier];
if (!pay_cell) {
pay_cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:Payment_CellIdentifier] autorelease];
}
pay_cell.textLabel.font=[UIFont systemFontOfSize:14];
if(indexPath.row == 0){
if ([[[[create_reservation_detail objectAtIndex:0] objectForKey:@"payment"] objectForKey:@"paypal"] isEqualToString:@""])
{
pay_cell.accessoryType=UITableViewCellAccessoryNone;
pay_cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
else
{
pay_cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
NSLog(@"accessory type ->%d",cell.accessoryType);
pay_cell.textLabel.text = @"PayPal";
pay_cell.selectionStyle = UITableViewCellSelectionStyleGray;
pay_cell.detailTextLabel.text=[[[create_reservation_detail objectAtIndex:0] objectForKey:@"payment"] objectForKey:@"paypal"];
pay_cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
pay_cell.detailTextLabel.numberOfLines = 0;
[pay_cell.detailTextLabel sizeToFit];
return pay_cell;
}
if(indexPath.row == 1){
if ([[[[create_reservation_detail objectAtIndex:0] objectForKey:@"payment"] objectForKey:@"manualCheck"] isEqualToString:@""])
{
pay_cell.accessoryType=UITableViewCellAccessoryNone;
pay_cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
else
{
pay_cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
NSLog(@"accessory type ->%d",cell.accessoryType);
pay_cell.textLabel.text = @"Manual Check";
pay_cell.selectionStyle = UITableViewCellSelectionStyleGray;
pay_cell.selectionStyle = UITableViewCellSelectionStyleGray;
pay_cell.detailTextLabel.text=[[[create_reservation_detail objectAtIndex:0] objectForKey:@"payment"] objectForKey:@"manualCheck"];
pay_cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
pay_cell.detailTextLabel.numberOfLines = 0;
[pay_cell.detailTextLabel sizeToFit];
return pay_cell;
}
if(indexPath.row == 2){
if ([[[[create_reservation_detail objectAtIndex:0] objectForKey:@"payment"] objectForKey:@"tranfer"] isEqualToString:@""])
{
pay_cell.accessoryType=UITableViewCellAccessoryNone;
NSLog(@"accessory type ->%d",UITableViewCellAccessoryCheckmark);
pay_cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
else
{
pay_cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
NSLog(@"accessory type ->%d",UITableViewCellAccessoryCheckmark);
pay_cell.textLabel.text = @"Wire / Transfer";
pay_cell.selectionStyle = UITableViewCellSelectionStyleGray;
pay_cell.selectionStyle = UITableViewCellSelectionStyleGray;
pay_cell.detailTextLabel.text=[[[create_reservation_detail objectAtIndex:0] objectForKey:@"payment"] objectForKey:@"tranfer"];
pay_cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
pay_cell.detailTextLabel.numberOfLines = 0;
[pay_cell.detailTextLabel sizeToFit];
return pay_cell;
}
if(indexPath.row == 3){
other.borderStyle=UITextBorderStyleRoundedRect;
other.placeholder=@"other\n";
other.autocorrectionType=UITextAutocorrectionTypeNo;
other.delegate=self;
other.autocapitalizationType=UITextAutocapitalizationTypeNone;
other.hidden=[[textFields objectAtIndex:2] intValue];
other.returnKeyType = UIReturnKeyDone;
[pay_cell addSubview:other];
pay_cell.textLabel.text = @"Other";
pay_cell.selectionStyle = UITableViewCellSelectionStyleGray;
return pay_cell;
}
}
else {
if(indexPath.row == 0){
static NSString *Button_CellIdentifier = @"Button_Cell";
UITableViewCell *button_cell = [tableView dequeueReusableCellWithIdentifier:Button_CellIdentifier];
if (button_cell == nil)
{
button_cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:Button_CellIdentifier] autorelease];
}
button_cell.backgroundView= [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"save_reservation_button.png"]] autorelease];
button_cell.selectedBackgroundView= [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"save_reservation_button.png"]] autorelease];
return button_cell;
}
}
return nil;
}
此致 Sathish所在
答案 0 :(得分:1)
您应该将自定义视图添加到块内的单元格
if (cell == nil) {
cell = [[[CreateReservationViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:RSVNIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// deal with your custom views here
}
例如,此代码将在单元格上再创建一个子视图。如果此单元格来自出列,则它已在此单元格上添加了emailTextField,并且以下代码将在此单元格上再添加一个emailTextField。
if(indexPath.row == 2){
//cell.selectionStyle = UITableViewCellSelectionStyleNone;
emailTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
... // assign emailTextField settings
cell.m_rsvn_name.text =@"Email";
[cell addSubview:emailTextField];
return cell;
}
答案 1 :(得分:0)
重叠发生的地方。表示在单元格项目或其他任何地方。并在代码中使用[cell addSubView]而不是使用[cell.contentView addSubView]