Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.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 NSTextAttachment未显示在今日通知中心小部件中_Ios_Objective C_Ios8_Ios8 Today Widget - Fatal编程技术网

Ios NSTextAttachment未显示在今日通知中心小部件中

Ios NSTextAttachment未显示在今日通知中心小部件中,ios,objective-c,ios8,ios8-today-widget,Ios,Objective C,Ios8,Ios8 Today Widget,我有一个通知中心小部件,它有一个带有表视图单元格的表视图。在单元格中,我有一个标签,我想显示文本+图像。作为NSTextAttachment包含的图像。我在应用程序中有以下代码: NSTextAttachment *attachment = [NSTextAttachment new]; attachment.image = [UIImage imageWithData:item.image]; NSAttributedString *itemImage = [NSAttributedStrin

我有一个通知中心小部件,它有一个带有表视图单元格的表视图。在单元格中,我有一个标签,我想显示文本+图像。作为NSTextAttachment包含的图像。我在应用程序中有以下代码:

NSTextAttachment *attachment = [NSTextAttachment new];
attachment.image = [UIImage imageWithData:item.image];
NSAttributedString *itemImage = [NSAttributedString attributedStringWithAttachment:attachment];
NSAttributedString *itemName = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@", item.name]];
NSMutableAttributedString *itemString = [[NSMutableAttributedString alloc] initWithAttributedString:itemImage];
[itemString appendAttributedString:itemName];
cell.nameLabel.attributedText = itemString;
这段代码在应用程序内部工作,但我也尝试在我的小部件中使用(因此今天是ViewController)。当显示在小部件中时,标签上不会显示任何图像。如果在运行此代码时停止,我可以看到attachment.image设置正确。我做错了什么?谢谢

试试换衣服

NSTextAttachment *attachment = [NSTextAttachment new];


这可能与本文中的问题相同:

在我设置了
cell.namelab.attributeText=itemString之后,它出现了我后来设置了cell.namelab.text=itemString,因此它覆盖了属性字符串

,不幸的是没有任何区别
NSTextAttachment *attachment = [NSTextAttachment alloc] initWithData:nil ofType:nil];