简体   繁体   中英

UITableView within UIScrollView surpassing bounds

I've had a growing headache from this for the last couple days. I'm trying to add some UITableViews to a scroll view, and page through the respective tables (like twitter's app, for example). I use macros for the screen's frame so I can be compatible with 3.5 and 4 inch screens:

#define screen_x 0
#define screen_y 0
#define screen_width [[UIScreen mainScreen] bounds].size.width
#define screen_height self.view.bounds.size.height
#define screen_frame CGRectMake(screen_x, screen_y, screen_width, screen_height)

I make an instance of a UIScrollView like so:

scroll_view = [[UIScrollView alloc] initWithFrame:screen_frame];
scroll_view.backgroundColor = [UIColor clearColor];
scroll_view.contentSize = CGSizeMake(screen_width * 3, screen_height);
scroll_view.bounds = screen_frame;
scroll_view.maximumZoomScale = 1.0;
scroll_view.minimumZoomScale = 1.0;
scroll_view.delegate = self;
scroll_view.bounces = false;
scroll_view.scrollsToTop = NO;
scroll_view.clipsToBounds = true;
scroll_view.pagingEnabled = true;
[self.view addSubview:scroll_view];

I make an instance and initialize a table like so:

table = [[example_table_view alloc] init_with_frame:CGRectMake(screen_width, 0, screen_width, screen_height) and_array:[information objectForKey:@"information"]];
table.clipsToBounds = true; //attempt to solve
table.bounds = broadcasts_table.frame; //attempt to solve
table.contentSize = scroll_view.contentSize; //attempt to solve
[scroll_view addSubview:table];

The issue is, while the scroll view's frame and bounds seem to be correct from the macros, the table insists on existing (vertically) outside of the scrollview, partially hidden by the UINavigationBar and UITabBar (it may be important to note I am using both in my application).

If anyone sees what I'm doing wrong, I'd appreciate it very much. Thanks!

The last time I checked the twitter app used something like a uipagevuewcontroller to swipe between views.

Not just a scroll view.

You might want to try experimenting with that first.

It's a lot kinder on memory usage also.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM