【发布时间】:2014-01-27 14:03:41
【问题描述】:
在该示例的末尾,我将子视图添加到 UIView,但未显示子视图。 UIView 正在显示(使其用于测试蓝色并且它在那里)如果我分别返回 rowLabel 或 rowImage 它们正在显示。但没有嵌入到 UIView 中。有什么想法吗?
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
NSDictionary *oneResultDict = [_postArray objectAtIndex:row];
NSData *tmpImageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[oneResultDict objectForKey:@"thumbnail"]]];
UIImage *tmpImage = [UIImage imageWithData:tmpImageData];
UIImageView *rowImage = [[UIImageView alloc] initWithImage:tmpImage];
rowImage.frame = CGRectMake(0, 0, 60, 60);
UILabel *rowLabel = [[UILabel alloc]initWithFrame:CGRectMake(80, 0, 200, 60)];
rowLabel.text = [oneResultDict objectForKey:@"title"];
UIView *rowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 160)];
[rowView insertSubview:rowImage atIndex:0];
[rowView insertSubview:rowLabel atIndex:1];
return rowView;
}
【问题讨论】:
-
已解决。 “*rowView”设置为 Y 高度 160。这有点大。当我将它降低到 80 时,一切都在正确的位置。现在我需要找出为什么会发生这种情况。其背后的规律是什么?
-
显示从您的方法返回的视图的
UIView可能会剪辑您的视图,尝试将clipsToBounds标志设置为NO。 - 它不会为您提供我假设的完整解决方案,但它可能会帮助您调试问题。 -
确实是 y 高度。如果我将所有 y 高度... rowLabel、rowImage 和 rowView 设置为相同的 60 大小。一切正常。 clipsToBound 也不起作用。没有效果。
标签: ios iphone objective-c uiview uipickerview