在該示例結束時我將子視圖添加到UIView,但是子目錄未顯示。 UIView顯示(使它成爲測試藍色,並且它在那裏)如果我單獨返回rowLabel或rowImage,它們顯示。但沒有嵌入到UIView中。有任何想法嗎?UIPickerView不顯示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-height 160.這在某種程度上是很大的。當我把它降到80時,所有人都在正確的地方。現在我需要找出原因。它背後的規則是什麼? – iOSNoob
顯示您的方法返回視圖的'UIView'可能* clip *您的視圖,請嘗試將'clipsToBounds'標誌設置爲'NO'。 - 它不會給你我假設的完整解決方案,但它可以幫助你調試問題。 –
這真的是y高度。如果我把所有的Y高度... rowLabel,rowImage和rowView大小相同的60。所有工作正常。 clipsToBound也沒有工作。沒有效果。 – iOSNoob