I got a view controller (lets call it MainViewContoller
) that's present 3 different tables (one in a time), user can tap a segment control to switch between those tables.
To present those 3 tables, MainViewContoller
has 3 other view controllers (A, B and C), each has a UITableView
as a subview and handle it's own data.
When a MainViewContoller
is loaded, it initiate controllers A, B and C, and add their tableViews to it's view:
- (void)viewDidLoad {
[super viewDidLoad];
ViewControllerA *vcA = [ViewControllerA alloc] init];
[self.view addSubview:vcA.view];
ViewControllerB *vcB = [ViewControllerB alloc] init];
[self.view addSubview:vcB.view];
ViewControllerC *vcC = [ViewControllerC alloc] init];
[self.view addSubview:vcC.view];
}
So for example when user tap the segment control and choose A, the MainViewContoller
hide tables B and C, and unhide table A. Something like this:
if (userTapOnA) {
self.viewControllerA.tableView.hidden = NO;
self.viewControllerB.tableView.hidden = YES;
self.viewControllerC.tableView.hidden = YES;
}
The problem:
When user tap the status bar I want that the current visible table will scroll to top.
This behavior is pretty basic and one gets it for free when using a regular view controller, but as you can see my view controller is not regular.
I suppose that by using other controllers view as MainViewContoller
view I break the default behavior, so my MainViewContoller
doesn't handle the status bar tap.
Someone got an idea how to solve that?
When you're at the bottom of a page, just tap the left side of your status bar to instantly scroll back up to the top. Tap the right trigger area, and you'll be taken directly to the bottom of any page.
Discussion. This property specifies how the safe area insets are used to modify the content area of the scroll view. The default value of this property is UIScrollView. ContentInsetAdjustmentBehavior. automatic .
This is directly from the UIScrollView header file:
/* When the user taps the status bar, the scroll view beneath the touch which is closest to the status bar will be scrolled to top, but only if its
scrollsToTop
property is YES, its delegate does not return NO fromshouldScrollViewScrollToTop
, and it is not already at the top. On iPhone, we execute this gesture only if there's one on-screen scroll view withscrollsToTop
== YES. If more than one is found, none will be scrolled. */@property(nonatomic) BOOL scrollsToTop; // default is YES.
So in your case, set all scrollsToTop to NO, except the one you want to enable at that particular moment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With