uiscrollview in uiview not scrolling

2019-09-03 14:50发布

I am using the storyboard to create a UIView that contains a UIScrollView that has many child items in it. these child items consist of a UIImageView that I am using as a background image for the UIScrollView, a series of UILabels that I populate programmatically, and a series of UITableViews that I populate with data obtained from a called set of library classes. I want all of this in my UIScrollView so the User can scroll through all of the information without having multiple views being displayed. I have browsed through a lot of postings here and have used a lot of the suggestions, but have been unable to successfully have the view scroll and allow the user to see all the data I'm attempting to present.

Here's a screen shot of the Storyboard followed by a shot of the attribute inspector for my UIScrollView

enter image description here

enter image description here

I'll also provide the .h and .m files

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

and here's my weatherController.m file. I'm going to only add the viewDidLoad method which is the only method containing code regarding my 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];
}

I would appreciate any help regarding what it is I'm either doing wrong or missing. If I set up my frame and contentSize to the following:

self.scrollView.frame = CGRectMake(0, 0, 320.0f, 480.0f);
self.scrollView.contentSize =CGSizeMake(320.0F, 1210.0F);

I do get the UIScrollView to scroll, but the image for the background is only the size of the frame, and none of the rest of the child content on the UIScrollView is displayed. It seems like it's allowing me to scroll but I'm only able to view the content that is viewable within the frame.

Again, thank you in advance for any help offered.

1条回答
Summer. ? 凉城
2楼-- · 2019-09-03 15:06

As the comments are suggesting, it's generally a bad idea to put a UITableView within a UIScrollView. I won't be too hard on you though, because there is a time and place where it is an acceptable solution. I'll let you judge if this time is now or not.

For reasons I still don't fully understand, UIScrollView behaves more like you expect it to if you enclose the entire contents in a single UIView that is as big as you want the UIScrollView to scroll.

查看更多
登录 后发表回答