表视图在真实设备上不刷新

时间:2015-05-06 07:07:10

标签: ios objective-c uitableview custom-cell row-height

我的表视图有问题。

当我选择行时,我的单元格高度正在变化并显示一些信息。如果我再次选择,它就会关闭。

在模拟器上工作就像一个魅力,但在真实设备上,第一部分工作正常,但是当我想要关闭它时,他正在执行代码但可能没有刷新tableView,因为我的信息保持显示。

真实设备的另一个问题:我的观点没有出现。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {


        return 4;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row ==1 &&show == YES) {
        return 50 + descLabel;

    }else if (indexPath.row == 2 && show2 == YES){

        return caracLabel;
    }

    {
    return 50;
    }
}




  -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        NSString *cellID = @"detailCell";
        switch (indexPath.row) {
            case 0:
                cellID = @"detailCell1";
                break;

            case 1:
                cellID = @"detailCell2";

                break;
            case 2:
                cellID = @"detailCell3";
                break;
            case 3:
                cellID = @"detailCell4";


            default:
                break;
        }

        detailCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];


        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.label.text = [self.array objectAtIndex:indexPath.row];
        cell.image1.image = [UIImage imageNamed:[NSString stringWithFormat:[self.imageArray objectAtIndex:indexPath.row]]];

        if (indexPath.row == 1) {

            if (show == NO) {
                cell.labelDef.hidden =YES;


            }
            }



        return cell;


    }



 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
        if (indexPath.row==1) {
        if (show == NO ) {

            detailCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"detailCell2" forIndexPath:indexPath];
            show=YES;
            cell.label.text = [self.array objectAtIndex:indexPath.row];
            cell.image1.image = [UIImage imageNamed:[NSString stringWithFormat:[self.imageArray objectAtIndex:indexPath.row]]];
            cell.labelDef.text=[self.desc objectAtIndex:pos];
            cell.labelDef.sizeToFit;
            cell.imageButton.image = [UIImage imageNamed:@"Play_Symbol_copie_5@3x.png"];
            cell.labelDef.frame = CGRectMake(10, 50, cell.labelDef.frame.size.width, cell.labelDef.frame.size.height);
            cell.labelDef.hidden = NO;
            UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 50, cell.frame.size.width, cell.labelDef.frame.size.height)];
            [view setBackgroundColor:[UIColor whiteColor]];
            [cell.contentView addSubview:view];
            [cell.contentView addSubview:cell.labelDef];
            descLabel = cell.labelDef.frame.size.height ;
    //        [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationMiddle];
            [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]]
                                  withRowAnimation:UITableViewRowAnimationNone];

            [self.tableView selectRowAtIndexPath:indexPath
                                        animated:NO
                                  scrollPosition:UITableViewScrollPositionNone];

            [self.tableView deselectRowAtIndexPath:indexPath animated:YES];


        }else{

            detailCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"detailCell2" forIndexPath:indexPath];
            show= NO;
            cell.label.text = [self.array objectAtIndex:indexPath.row];
            cell.image1.image = [UIImage imageNamed:[NSString stringWithFormat:[self.imageArray objectAtIndex:indexPath.row]]];
            cell.imageButton.image = [UIImage imageNamed:@"Play_Symbol_copie_2@3x.png"];
            cell.labelDef.hidden = YES;
    //        [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationMiddle];
            [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]]
                                  withRowAnimation:UITableViewRowAnimationNone];

            [self.tableView selectRowAtIndexPath:indexPath
                                        animated:NO
                                  scrollPosition:UITableViewScrollPositionNone];

            [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
            }
        }else if (indexPath.row == 2) {
            if ( show2 == NO) {
                detailCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"detailCell3"forIndexPath:indexPath];
                show2=YES;
                cell.label.text = [self.array objectAtIndex:indexPath.row];
                cell.image1.image = [UIImage imageNamed:[NSString stringWithFormat:[self.imageArray objectAtIndex:indexPath.row]]];
                cell.imageButton.image = [UIImage imageNamed:@"Play_Symbol_copie_5@3x.png"];
                NSArray *firstWords = [[self.carac objectAtIndex:pos] componentsSeparatedByString:@"\n"];
                UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 50, cell.frame.size.width  , 100)];
                [view1 setBackgroundColor:[UIColor colorWithRed:246/256.0 green:245/256.0 blue:241/256.0 alpha:1]];
                [cell.contentView addSubview:view1];

                caracLabel = 50;
                for (int i = 0; i <firstWords.count; i++) {
                        NSArray *array = [[firstWords objectAtIndex:i]componentsSeparatedByString:@"/"];

                        UILabel *label = [[UILabel alloc]initWithFrame: CGRectMake(10, caracLabel, 90, 20)];

                        label.text = [array objectAtIndex:0];
                        label.textColor = [UIColor colorWithRed:150/256.0 green:150/256.0 blue:150/256.0 alpha:1];
                        label.numberOfLines = 0;
                        [label sizeToFit];

                        [cell.contentView addSubview:label];

                        UILabel *label1 = [[UILabel alloc]initWithFrame: CGRectMake(110, caracLabel, 205, 20)];

                        label1.text = [array objectAtIndex:1];
                        label1.textColor = [UIColor colorWithRed:150/256.0 green:150/256.0 blue:150/256.0 alpha:1];
                        label1.numberOfLines = 0;
                        [label1 sizeToFit];

                        caracLabel = caracLabel + label1.frame.size.height;
                    if (i != firstWords.count - 1) {

                    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, caracLabel, cell.frame.size.width, 1)];
                    [view setBackgroundColor:[UIColor whiteColor]];
                    caracLabel =caracLabel+2;
                        [cell.contentView addSubview:view];
                    }
                        [cell.contentView addSubview:label1];

                }

                UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 50, 1, caracLabel - 50)];
                [view setBackgroundColor:[UIColor whiteColor]];
                [cell.contentView addSubview:view];
                view1.frame = CGRectMake(0, 50, cell.frame.size.width, caracLabel-50);

    //            [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationMiddle];
                [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]]
                                      withRowAnimation:UITableViewRowAnimationNone];

                [self.tableView selectRowAtIndexPath:indexPath
                                            animated:NO
                                      scrollPosition:UITableViewScrollPositionNone];

                [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
            } else {
                detailCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"detailCell3"forIndexPath:indexPath];
                show2= NO;
                cell.label.text = [self.array objectAtIndex:indexPath.row];
                cell.image1.image = [UIImage imageNamed:[NSString stringWithFormat:[self.imageArray objectAtIndex:indexPath.row]]];
                cell.imageButton.image = [UIImage imageNamed:@"Play_Symbol_copie_2@3x.png"];

    //            [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationMiddle];
                [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]]
                                      withRowAnimation:UITableViewRowAnimationNone];

                [self.tableView selectRowAtIndexPath:indexPath
                                            animated:NO
                                      scrollPosition:UITableViewScrollPositionNone];

                [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
            }
        }else
        if (indexPath.row == 3){
            NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[self.wiki objectAtIndex:pos]]];
            UIWebView *video = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - +50)];
            [video loadRequest:request];
            video.delegate=self;
            showWeb = YES;
            UIActivityIndicatorView *actInd=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
            actInd.color=[UIColor blackColor];
            [actInd setCenter:self.view.center];
            self.activityIndicator=actInd;
            [self.view addSubview:video];

            [video addSubview:self.activityIndicator];
        }

    }

这是在模拟器上查找/工作的方式: 关闭 - closed

描述 - description

caracteristics- caracteristics

这就是真正的设备: 描述 - enter image description here

caracteristics - enter image description here

关闭 - enter image description hereenter image description here

我不知道这是否有问题,但是我在真实设备中第一次按下后行正在改变颜色。为什么?有什么想法吗?

1 个答案:

答案 0 :(得分:0)

如果一切在模拟器中运行良好但在设备中没有运行,则检查“dequeueReusableCellWithIdentifier”/“CellID”值,因为模拟器不区分大小写,但设备区分大小写。

可能没有找到你的手机ID,所以它发生了,我不确定,但只检查一次。