ios - iOS 8.0 升级后 UILabel 不显示

标签 ios objective-c xcode

今天早上刚刚更新到 iOS 8.0。我有一段代码创建了一些标签并将它们显示在一些图像旁边的屏幕上。更新之前一直运行良好。现在标签和图像不显示。有人可以帮忙吗,因为我已经尝试了我能想到的所有方法,但没有任何方法可以解决我的问题,并且找不到其他有类似问题的人。代码附在下面。

UIView *labelView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, kCategoryLabelHieght)];
labelView.backgroundColor = [self colorWithHexString:@"2D2D2D"];

UILabel *categoryTitle = [[UILabel alloc] initWithFrame:CGRectMake(40, 0, 200, kCategoryLabelHieght)];
categoryTitle.textAlignment = NSTextAlignmentLeft;
categoryTitle.text = text;
categoryTitle.font = [UIFont fontWithName:@"HelveticaNeue" size:14];

codeAppDelegate *appDelegate = (codeAppDelegate *)[[UIApplication sharedApplication] delegate];
NSArray *fetchedCategory = [appDelegate getCategoryByName:text];

UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake(10, 2, 20, 20)];

if(fetchedCategory.count)
{
    for (int t=0; t<fetchedCategory.count; t++) {
        Dealcategory_List *catList = [fetchedCategory objectAtIndex:t];
        NSString *titleImage = [self URLEncodeString:[NSString stringWithFormat:@"%@",catList.image]];
        NSURL *url = [NSURL URLWithString:titleImage];
        NSData *data = [NSData dataWithContentsOfURL:url];
        UIImage *imgTabs = [UIImage imageWithData:data];
        //        [header2 setImage:imgTabs forState:UIControlStateNormal];
        [imgTabs resizableImageWithCapInsets: UIEdgeInsetsMake(5, 10, 2, 0) resizingMode: UIImageResizingModeTile];

        img.image= imgTabs;
    }
}
else
{
    NSArray *fetchedNewsCategory = [appDelegate getNewsCategoryByName:text];

    if(fetchedNewsCategory.count > 0)
    {
        for (int t=0; t<fetchedNewsCategory.count; t++) {
            News_Categories *catList = [fetchedNewsCategory objectAtIndex:t];
            NSString *titleImage = [self URLEncodeString:[NSString stringWithFormat:@"%@",catList.category_image]];
            NSURL *url = [NSURL URLWithString:titleImage];
            NSData *data = [NSData dataWithContentsOfURL:url];
            UIImage *imgTabs = [UIImage imageWithData:data];
            //        [header2 setImage:imgTabs forState:UIControlStateNormal];
            [imgTabs resizableImageWithCapInsets: UIEdgeInsetsMake(10, 10, 2, 0) resizingMode: UIImageResizingModeTile];

            img.image= imgTabs;
        }
    }
    else
    {
        NSArray *fetchedCompetition = [appDelegate getCompetitionByName:text];

        if(fetchedCompetition.count > 0)
        {
            for (int t=0; t<fetchedCompetition.count; t++) {
                Competitions_List *catList = [fetchedCompetition objectAtIndex:t];
                NSString *titleImage = [self URLEncodeString:[NSString stringWithFormat:@"%@",catList.competition_tab_image]];
                NSURL *url = [NSURL URLWithString:titleImage];
                NSData *data = [NSData dataWithContentsOfURL:url];
                UIImage *imgTabs = [UIImage imageWithData:data];
                //        [header2 setImage:imgTabs forState:UIControlStateNormal];
                [imgTabs resizableImageWithCapInsets: UIEdgeInsetsMake(10, 10, 2, 0) resizingMode: UIImageResizingModeTile];

                img.image= imgTabs;

                break;
            }
        }
    }
}

categoryTitle.textColor = color;
[labelView addSubview:img];
[labelView addSubview:categoryTitle];

[self.contentView addSubview:labelView];

最佳答案

UIView *labelView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, kCategoryLabelHieght)];

您正在定义一个 UIView 但分配一个 UILabel。 iOS 8 对此类错误的容忍度较低。尝试将其更改为

UIView *labelView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, kCategoryLabelHieght)];

关于ios - iOS 8.0 升级后 UILabel 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26111194/

相关文章:

ios - 如何知道应用程序是从特定链接安装的

ios - 如何下载 xcode 6 测试版?以及如何将 xcode 5 和 xcode 6 保存在同一台机器上?

ios - 外部附件流在 100% 的时间都不起作用

ios - iOS-Twitter连接问题:“操作无法完成。 ( cocoa 错误3840。)”

objective-c - iPhone - 找不到我的应用程序

iphone - 如何访问类中的ABRecordRef值?

ios - 最后一个单元格不断出现在 myUITableView 上

ios - 重新安装后无法在 macOS 上使用 `-R` 递归更改权限

objective-c - 如何从 NSMatrix 获取 NSButton (CheckBox) 的状态

iphone - 如何访问 Interface Builder( Storyboard)中的其他 UI 元素?