任何人都可以解释以下在 iOS(特别是 iOS7)上观察到的行为:
我有一个自定义 UITableViewCell 类。为简单起见,以下是该类的相关方法,包括layoutSubviews:
// CustomCell.h
@interface CustomCell : UITableViewCell {
UITextView *textView;
UIImageView *backgroundImage;
}
@property (nonatomic, retain) UITextView *textView;
@property (nonatomic, retain) UIImageView *backgroundImage;
@end
// CustomCell.m
- (void) layoutSubviews
{
[super layoutSubviews];
if (self.message.isIncoming)
{
self.textView.textColor = [UIColor whiteColor];
self.backgroundImage.image = [UIImage imageNamed:@"incomingImage.png"];
}
else
{
self.textView.textColor = [UIColor blackColor];
self.backgroundImage.image = [UIImage imageNamed:@"outgoingImage.png"];
}
}
这是它的设置方式:
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Message *chatMessage = [messages objectAtIndex:indexPath.row];
CustomCell *cell = (CustomCell*)[theTableView dequeueReusableCellWithIdentifier:CELL_IDENTIFIER forIndexPath:indexPath];
[cell setMessage:chatMessage];
return cell;
}
textView 和 backgroundImage 的内容和定位都是在其他地方完成的,并且 100% 的时间都正确完成。
谁能解释一下我会看到带有 whiteText 的传入消息,但使用了传出图像背景的场景?然后一秒钟后,背景正确更新为incomingImage,用户看到背景变化。
基本上我看到一个单元格在文本正确且 textColor 正确的地方被重新使用,但有时 backgroundImage 不正确。我想知道应用 UIImageView 的 .image 属性是否存在某种延迟?我知道 layoutSubviews 被调用,因为如果它不是 textColor 将不正确。只是 UIImageView 的图像属性有时会不正确或不会立即更新。
请注意,textView 和 backgroundImage 都是我添加为自定义 UITableViewCell 的 contentView 的子视图的自定义视图