【发布时间】:2013-10-27 18:05:22
【问题描述】:
我正在使用情节提要创建一个UIView,其中包含一个UIScrollView,其中包含许多子项。这些子项包括一个UIImageView,我用作UIScrollView 的背景图像,一系列UILabels,我以编程方式填充,以及一系列UITableViews,我用从调用的数据获得的数据填充库类集。我希望所有这些都在我的UIScrollView 中,这样用户就可以滚动浏览所有信息,而不会显示多个视图。我在这里浏览了很多帖子并使用了很多建议,但无法成功滚动视图并允许用户查看我尝试呈现的所有数据。
这是 Storyboard 的屏幕截图,然后是我的 UIScrollView 的属性检查器的截图
我还将提供 .h 和 .m 文件
weatherController.h
#import <UIKit/UIKit.h>
#import "WeatherParser.h"
#import "WeatherLocation.h"
#import "WeatherImg.h"
#import "WeatherWind.h"
#import "ForcastDay.h"
#import "ForecastItem.h"
#import "Condition.h"
#import "Atmo.h"
#import "Astro.h"
@class WeatherParser;
@class WeatherParserDelegate;
@class WeatherLocation;
@class WeatherImg;
@class WeatherWind;
@class ForcastDay;
@class ForecastItem;
@class Condition;
@class Atmo;
@class Astro;
@interface weatherController : UIViewController <UITableViewDataSource,UITableViewDelegate,WeatherParserDelegate>{
WeatherParser * _rssParser;
bool loadingEvents;
}
@property (nonatomic, retain) WeatherParser * rssParser;
@property bool loadingEvents;
@property (retain, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UILabel *cityLabel;
@property (weak, nonatomic) IBOutlet UILabel *state_countryLabel;
@property (weak, nonatomic) IBOutlet UILabel *currHighLabel;
@property (weak, nonatomic) IBOutlet UILabel *currLowLabel;
@property (weak, nonatomic) IBOutlet UILabel *currTempLabel;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIImageView *logoImageView;
@property (weak, nonatomic) IBOutlet UILabel *logoLabel;
@property (weak, nonatomic) IBOutlet UITableView *forecastTableView;
@property (weak, nonatomic) IBOutlet UITableView *atmoTableView;
@property (weak, nonatomic) IBOutlet UITableView *windTableView;
@property (weak, nonatomic) IBOutlet UITableView *astroTableView;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *sidebarButton;
@property (nonatomic, retain) NSMutableArray *forecastDays;
@property bool logoSet;
@end
这是我的 weatherController.m 文件。我将只添加viewDidLoad 方法,这是唯一包含与我的UIScrollView 有关的代码的方法。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
_scrollView.delegate = self;
// self.scrollView.frame = CGRectMake(0, 0, 320.0f, 480.0f);
self.scrollView.contentSize =CGSizeMake(320.0F, 480.0F); //(320, 1210)];
[_scrollView setScrollEnabled:YES];
}
如果我做错了什么或遗漏了什么,我将不胜感激。如果我将frame 和contentSize 设置为以下内容:
self.scrollView.frame = CGRectMake(0, 0, 320.0f, 480.0f);
self.scrollView.contentSize =CGSizeMake(320.0F, 1210.0F);
我确实让UIScrollView 滚动,但背景图像只是框架的大小,UIScrollView 上的其余子内容均不显示。似乎它允许我滚动,但我只能查看在 frame 中可见的内容。
再次感谢您提供的任何帮助。
【问题讨论】:
-
你为什么要把tableViews放在scrollViews里?!
-
@paulrehkugler 这是一种简单而有效的信息显示方式,无论是否使用 tableViews,这些信息都将以表格形式显示。此外,这些表格只有 3-5 行长。它们不大,不会占用太多空间。
标签: iphone ios uiview uiscrollview