我正在尝试将 web 视图放在滚动视图中的图像下方。此代码导致空白屏幕。我敢肯定这非常简单(我是初学者),但有人能指出我的错误吗?
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = [self.detailItem title];
//self.webView = [[UIWebView alloc] init];
//self.imageView = [[UIImageView alloc] init];
UIImage* image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[self.detailItem imageURL]]]];
self.imageView.image = image;
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[self.detailItem url]]]];
[self.scrollView addSubview:self.imageView];
[self.scrollView addSubview:self.webView];
self.imageView.frame = CGRectMake(0, 770, 320, 230);
[self.webView setFrame:CGRectMake(0, 0, 320, 770)];
CGFloat scrollViewHeight = 1000.0f;
/*
for (UIView* view in scrollView.subviews)
{
NSLog(@"%f",view.frame.size.height);
scrollViewHeight += view.frame.size.height;
}
*/
[scrollView setContentSize:(CGSizeMake(320, scrollViewHeight))];
NSLog(@"%f", self.imageView.frame.size.height);
NSLog(@"%f", self.webView.frame.size.height);
[self configureView];
}
从.h
@interface DetailViewController : UIViewController <UIScrollViewDelegate>{
UIScrollView* scrollView;
}
@property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
@property (strong, nonatomic) id detailItem;
@property (nonatomic, strong) UIWebView *webView;
@property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
@property (nonatomic, strong) UIImageView *imageView;
@end