ios - uitableviewcells 与 3 个重叠中的前 2 个单元重叠

标签 ios uitableview

我一直试图弄清楚我的单元格是否重叠,但我失败了。我的表包含 3 个条目 - 前 2 个条目重叠,但第 3 个条目不重叠。我在网上搜索了一下,发现变量应该在本地定义。我采纳了这个建议,但遗憾的是,它没有帮助。

下面是代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIColor *rung;
    if (indexPath.row%2 == 0) {
      //  0.662745 0.662745 0.662745
        rung=[UIColor colorWithRed:0.802745 green:0.802745 blue:0.802745 alpha:1];
        color=NO;
    }
    else {
       // 0.972549 0.972549 1
    //0.411765 0.411765 0.411765
        rung=[UIColor colorWithRed:0.862745 green:0.862745 blue:0.862745 alpha:1];
        color=YES;
    }



    //static NSString *MyIdentifier = @"Identifier";
    NSLog(@"====IndexPath is %d",indexPath.row);

    ChatSlideDC *slide = [[HMMainManager getSharedInstance].currentMeeting.resumedChatMessages objectAtIndex:indexPath.section];


    ChatMessageDC *message;

    message = [[slide ChatMessageArray]objectAtIndex:indexPath.row];
    NSLog(@"%i",indexPath.row);

    NSLog(@"%@",message.senderEmail);
    NSLog(@"====Message Type is %@",message.MessageType);
    //--storing Email-ID for Pics
    UIImage *avatar;
    if(message.AttendeeID)
    {
        avatar= [(AppDelegate *)[[UIApplication sharedApplication]delegate] getAvatar:message.AttendeeID andAttendeEmail:message.senderEmail];
    }



    //
    NSLog(@"%@",message.Message);
    if ([message.MessageType isEqualToString: @"0"] || [message.MessageType isEqualToString:@"1"]) {
        ChatCustomCell * cell = (ChatCustomCell *) [tableView dequeueReusableCellWithIdentifier:@"ChatCustomCell"];

        if (cell == nil) {

            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ChatCustomCell" owner:self options:nil];
            cell = (ChatCustomCell*)[nib objectAtIndex:0];
            }
    //    cell.backgroundImage.backgroundColor=rung;
        UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
        view.backgroundColor = rung;
        view.opaque = YES;
        cell.backgroundView = view;
        [view release];
        //cell.backgroundColor=rung;
        cell.lblSaid.text =@"Said";
        cell.lblName.text =message.SenderName;
        cell.lblText.text =message.Message;


        NSLog(@"manager strID: %@ chat cell attendeeID %@",[HMMainManager getSharedInstance].currentMeeting.strAttendeeID,message.AttendeeID);
        NSLog(@"%@ == %@",message.AttendeeID,[HMMainManager getSharedInstance].currentMeeting.strAttendeeID);

        [cell.imgThumbUserPic setImage:[UIImage imageNamed:@"updateProfileIco.png"]];

//        if ([message.AttendeeID isEqualToString:[HMMainManager getSharedInstance].currentMeeting.strAttendeeID]) {
//            cell.imgThumbUserPic.image = [MainManager getSharedInstance].userManager.userImage;
            cell.imgThumbUserPic.image = avatar;
//        }

        cell.selectionStyle = UITableViewCellEditingStyleNone;
   //     [message release];
        return cell;
    }
    if ([message.MessageType isEqualToString:@"2"] || [message.MessageType isEqualToString:@"3"] ) {
        if ([message.MessageType isEqualToString:@"3"] || (message.question && [message.question length]>0)) {
            //show asnwer cell
//            AnswerCustomCell * cell = (AnswerCustomCell *) [tableView dequeueReusableCellWithIdentifier:@"AnswerCustomCell"];
   NSMutableArray *answerquestArray=   [[[HMMainManager getSharedInstance] currentMeeting]questionAnswerArray];

        //    UITableViewCell *newCell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"abc"];
            int width=300,height=164,totalHeight;;
        //    AnswerMultipleCell * cell;
            int questionIndex;
            QuestionWithAnswers *qwa;
            for (int i=0;i<answerquestArray.count;i++) {

                qwa=[answerquestArray objectAtIndex:i];
                NSLog(@"");
                if ([qwa.questionID isEqualToString:message.QuestionID]) {

                    break;
                }
            }//end for    


         //               newCell.frame=CGRectMake(0, totalHeight, width, height);
            ChatMessageDC *answersInArr;
            int i=0;
            for (i=0;i<[qwa.answersMArray count];i++) {

                answersInArr=[qwa.answersMArray objectAtIndex:i];
                if([answersInArr.MessageId isEqualToString:message.MessageId])
                {
                    break;
                }

            }
      AnswerMultipleCell *     cell = (AnswerMultipleCell *) [tableView dequeueReusableCellWithIdentifier:@"AnswerMultipleCell"];
            if (cell == nil) 
            {              
//                NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AnswerCustomCell" owner:self options:nil];
//                cell = (AnswerCustomCell*)[nib objectAtIndex:0];
                NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AnswerMultipleCell" owner:self options:nil];
                cell = (AnswerMultipleCell*)[nib objectAtIndex:0];
            }
            UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
            view.backgroundColor = rung;
            view.opaque = YES;
            cell.backgroundView = view;
            [view release];
            //answer here goes

            cell.answerTxt.text=answersInArr.Message;
            cell.userName.text=answersInArr.SenderName;
            [cell.answerTxt flashScrollIndicators];

            //question


            NSLog(@"%@",message.MessageId);

            NSLog(@"manager strID: %@ ans cell attendeeID %@",[HMMainManager getSharedInstance].currentMeeting.strAttendeeID,message.AttendeeID);



            [cell.userPic setImage:[UIImage imageNamed:@"updateProfileIco.png" ]];
//            [cell.quePic setImage:[UIImage imageNamed:@"updateProfileIco.png" ]];



            //if ([message.AttendeeID isEqualToString:[HMMainManager getSharedInstance].currentMeeting.strAttendeeID]) {
                  avatar= [(AppDelegate *)[[UIApplication sharedApplication]delegate] getAvatar:[qwa.attendeIDMArray objectAtIndex:i] andAttendeEmail:[qwa.attendeEmails objectAtIndex:i]];         
                 NSLog(@"----------:: %@ == %@ and message:%@",message.AttendeeID ,[HMMainManager getSharedInstance].currentMeeting.strAttendeeID,message.Message);
//                cell.ansPic.image = [MainManager getSharedInstance].userManager.userImage;
                cell.userPic.image = avatar;

      //      } 
            NSLog(@"manager strID: %@ ans cell attendeeID %@",[HMMainManager getSharedInstance].currentMeeting.strAttendeeID,message.QuestionID);




  //            {

                NSLog(@"------------:: %@ == %@ and message:%@",message.questionAttendeeID ,[HMMainManager getSharedInstance].currentMeeting.strAttendeeID,message.Message);

//                cell.quePic.image = [MainManager getSharedInstance].userManager.userImage;
//                cell.quePic.image = avatar;
//            }


//}//end answersArray
            return cell;
        }
        else {
            //show question cell

            QuestionCustomCell * cell = (QuestionCustomCell *) [tableView dequeueReusableCellWithIdentifier:@"QuestionCustomCell"];

            if (cell == nil) {
                NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"QuestionCustomCell" owner:self options:nil];
                cell = (QuestionCustomCell*)[nib objectAtIndex:0];
            }
            UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
            view.backgroundColor = rung;
            view.opaque = YES;
            cell.backgroundView = view;
            [view release];
            cell.lblSaid.text =@"Asked";
            cell.lblName.text =message.SenderName;

            NSLog(@"Question is %@", message.question);

            cell.lblText.text =message.Message;
            [cell.lblText flashScrollIndicators];
//            cell.lblAnswerQuestion.hidden = NO;
            if (!message.answered) {
                cell.lblAnswerQuestion.hidden = NO;
                cell.userInteractionEnabled = YES;
            }else {
                cell.lblAnswerQuestion.hidden = YES;
                cell.userInteractionEnabled = NO;
            }

//            cell.userInteractionEnabled = YES;
            [[HMMainManager getSharedInstance].currentMeeting.questionDict setObject:message.AttendeeID forKey:message.MessageId];  

            NSLog(@"manager strID: %@ ques cell attendeeID %@",[HMMainManager getSharedInstance].currentMeeting.strAttendeeID,message.AttendeeID);


            [cell.imgThumbUserPic setImage:[UIImage imageNamed:@"updateProfileIco.png"]];
  //          if ([message.AttendeeID isEqualToString:[HMMainManager getSharedInstance].currentMeeting.strAttendeeID]) {
//                cell.imgThumbUserPic.image = [MainManager getSharedInstance].userManager.userImage;
                cell.imgThumbUserPic.image = avatar;
  //          }

            cell.tvAnswer.delegate = self;

            NSMutableString* finalSec = [NSString stringWithFormat:@"%d",indexPath.section];

            for (NSInteger x=0; x<3; x++) {

                if (finalSec.length <3) {
                    finalSec = [NSString stringWithFormat:@"0%@",finalSec];
                }

            }

            NSLog(@"%@", finalSec);

            NSString* tag = [NSString stringWithFormat:@"%d%@",indexPath.row+1, finalSec];

             NSLog(@"tag value %d",[tag intValue]);

            cell.btnAnswer.tag = [tag intValue];//indexPath.row + 1000 + indexPath.section;
            cell.tvAnswer.tag = [tag intValue];
            cell.selectionStyle = UITableViewCellEditingStyleNone;
            [cell.btnAnswer addTarget:self action:@selector(answerButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

    //        [message release];
            return cell;

        }

    }
 //   [message release];
    return nil;
}

最佳答案

如果您有自定义(非 44 点高度)单元格,则需要实现 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

关于ios - uitableviewcells 与 3 个重叠中的前 2 个单元重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13196818/

相关文章:

ios - SwiftUI - 在具有透明度的 View 上剪切阴影

iphone - 在 obj-c 中使用正则表达式在字符串中搜索模式

iOS 在 UITableViewCell 中均匀间隔 5 个标签

ios - 如何根据选定的单元格将 segue 推送到特定的 View Controller ?

ios - UITableView 不调用 cellForRowAtIndexPath

iphone - UITableView 单元格中的 UILabel 在 iOS7 中相互重叠

iphone - 如何创建一个具有 NavControllers 并在其中保存 tableVC 的 Tabbar?

ios - Visual Studio 中没有 iphone 设备

ios - SpriteKit 使 2 个 SKShapeNode 粘在一起?

ios - drawTextInRect : in UITextView class