Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 我在UILabel中粘贴文本时出现了一些错误_Ios_Json_Xcode_Uitableview_Cell - Fatal编程技术网

Ios 我在UILabel中粘贴文本时出现了一些错误

Ios 我在UILabel中粘贴文本时出现了一些错误,ios,json,xcode,uitableview,cell,Ios,Json,Xcode,Uitableview,Cell,我在tableViewCell中创建的UILabel有一些问题。所以我有了带有Textlabel、detail text的tableView,以及我创建的第三个单元格标签。因此,我从JSON获取信息并粘贴到第三个标签上,其结果如下: 但当我尝试滚动表格时,时间文本出现了一些问题: 所以,当我把UIColor白色作为背景添加到这个标签上时,我并没有这个数字。请问我做错了什么 我将代码添加到tableView中 -(UITableViewCell *)tableView:(UITableView

我在tableViewCell中创建的UILabel有一些问题。所以我有了带有Textlabel、detail text的tableView,以及我创建的第三个单元格标签。因此,我从JSON获取信息并粘贴到第三个标签上,其结果如下:

但当我尝试滚动表格时,时间文本出现了一些问题:

所以,当我把UIColor白色作为背景添加到这个标签上时,我并没有这个数字。请问我做错了什么

我将代码添加到tableView中

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{



    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];




    if(! cell)
    {
        cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]autorelease];

               cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]autorelease];

    }

    cell.textLabel.text = [[array objectAtIndex:indexPath.row]objectForKey:@"song"];

    cell.detailTextLabel.text = [[array objectAtIndex:indexPath.row]objectForKey:@"artist"];

    UILabel *mainLabel;

    //frame=CGRectMake(Позиция по X, Позиция по Y, Размеры ширина, Раздел высота)

    mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(70, 58, 220.0, 15.0)] autorelease];

    mainLabel.font = [UIFont systemFontOfSize:14.0];

    mainLabel.textColor = [UIColor blackColor];
    [cell.contentView addSubview:mainLabel];

    mainLabel.text = [[array objectAtIndex:indexPath.row]objectForKey:@"start"];

    [cell.imageView setImageWithURL:[NSURL URLWithString:[[array objectAtIndex:indexPath.row] objectForKey:@"image"]] placeholderImage:[UIImage imageNamed:@"1@2x.png"]];



    cell.textLabel.textColor = [UIColor whiteColor];

    cell.detailTextLabel.textColor = [UIColor whiteColor];

    mainLabel.backgroundColor = [UIColor clearColor];

    mainLabel.textColor = [UIColor whiteColor];

    [tableTrack setBackgroundView:nil];

    [TrackTableView setBackgroundView:nil];

    tableTrack.backgroundColor = [UIColor clearColor];

    TrackTableView.backgroundColor = [UIColor clearColor];

    UIFont *f = [UIFont fontWithName:@"Helvetica 35 Thin" size:18.0f];

    cell.textLabel.font = f;

    UIFont *f2 = [UIFont fontWithName:@"Helvetica 35 Thin" size:14.0f];

    cell.detailTextLabel.font = f2;

    UIFont *f3 = [UIFont fontWithName:@"Helvetica 35 Thin" size:14.0f];

    mainLabel.font = f3;


    self.tableTrack.separatorStyle = UITableViewCellSeparatorStyleNone;

    UIView *separatorView = [[UIView alloc] initWithFrame:CGRectMake(10, 74, 1024, 1)];
    separatorView.layer.borderColor = [UIColor whiteColor].CGColor;
    separatorView.layer.borderWidth = 0.5;
    [cell.contentView addSubview:separatorView];

    self.TrackTableView.separatorStyle = UITableViewCellSeparatorStyleNone;





    return cell;
}

错误在于您在if条件if(cell==nil)之外的(else部分)中分配了标签。在第一次创建单元时,只应创建一次标签


当我们运行代码时,控件检查单元格是否为nil或是否有任何值。如果我们每次都在else部分分配标签(同时滚动),那么每次您都在创建一个新标签。如果我们在If条件下分配它,则标签只为每个单元格分配一次,并且在滚动时只更新文本值。

请尝试此委托方法。。问题是,在创建标签时,您正在将标签添加到“仅在中添加子视图”的标题单元格中…请尝试以下代码

  -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {



        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];






         if(! cell)
            {
                cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]autorelease];


         mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(70, 58, 220.0, 15.0)] autorelease];

            mainLabel.font = [UIFont systemFontOfSize:14.0];

            mainLabel.textColor = [UIColor blackColor];
            [cell.contentView addSubview:mainLabel];

        UIView *separatorView = [[UIView alloc] initWithFrame:CGRectMake(10, 74, 1024, 1)];
            separatorView.layer.borderColor = [UIColor whiteColor].CGColor;
            separatorView.layer.borderWidth = 0.5;
            [cell.contentView addSubview:separatorView];
            }

            cell.textLabel.text = [[array objectAtIndex:indexPath.row]objectForKey:@"song"];

            cell.detailTextLabel.text = [[array objectAtIndex:indexPath.row]objectForKey:@"artist"];

            UILabel *mainLabel;

            //frame=CGRectMake(Позиция по X, Позиция по Y, Размеры ширина, Раздел высота)


            mainLabel.text = [[array objectAtIndex:indexPath.row]objectForKey:@"start"];

            [cell.imageView setImageWithURL:[NSURL URLWithString:[[array objectAtIndex:indexPath.row] objectForKey:@"image"]] placeholderImage:[UIImage imageNamed:@"1@2x.png"]];



            cell.textLabel.textColor = [UIColor whiteColor];

            cell.detailTextLabel.textColor = [UIColor whiteColor];

            mainLabel.backgroundColor = [UIColor clearColor];

            mainLabel.textColor = [UIColor whiteColor];

            [tableTrack setBackgroundView:nil];

            [TrackTableView setBackgroundView:nil];

            tableTrack.backgroundColor = [UIColor clearColor];

            TrackTableView.backgroundColor = [UIColor clearColor];

            UIFont *f = [UIFont fontWithName:@"Helvetica 35 Thin" size:18.0f];

            cell.textLabel.font = f;

            UIFont *f2 = [UIFont fontWithName:@"Helvetica 35 Thin" size:14.0f];

            cell.detailTextLabel.font = f2;

            UIFont *f3 = [UIFont fontWithName:@"Helvetica 35 Thin" size:14.0f];

            mainLabel.font = f3;


            self.tableTrack.separatorStyle = UITableViewCellSeparatorStyleNone;



            self.TrackTableView.separatorStyle = UITableViewCellSeparatorStyleNone;





            return cell;
        }

请提供数据源代理方法!你想看我的代码项目吗?不只是CellForRowatinedexPath委托方法在我的情况下如何?如果可以帮我的忙?