Handle touch events when UITableView placed over UITableView - objective-c

I have a SplitViewController with a UITableView on the left.
I am trying to place a small UITableView over a part of the screen, but touches seem to be handled strangely when the small UITableView is placed over the left UITableView.
I am placing the UITableView over the SplitView like this:
MenuViewController *menu = [[MenuViewController alloc] initWithNibName:nil bundle:nil];
[self.splitViewController.view addSubview:menu.view];
Some touches are registered by menu.view, while sometimes I am able to scroll the underlying view "through" menu.view.
So my question is: what decides which view reacts to touch events?

So I found that the solution was, that I needed to set clipsToBounds=YES on the views contained in menu.view.
Not sure I fully understand the solution, but it works.

Related

UINavigationController UIToolBar does not show up in my views

My UINavigationController contains a UIToolBar with 3 UIBarBottomItems - It has all been drag/drop designed in the storyboard. I want this UIToolbar to be shared on all my views. I have therefore set checked the "shows toolbar". But when I run it the UIToolBar is empty in all of my views. What could be the reason for this ?
I realize this is an old thread but I've just been struggling with this for a couple hours and finally figured out what was wrong. It was something simple so thought I would share. I was calling [self.navigationController setToolbarHidden:NO]; in viewDidLoad. The problem was that viewDidLoad is called before the view controller is pushed onto the navigationController so self.navigationController is nil. I moved the code to viewWillAppear: method and it worked.
UINavigationController have default toolbar. which you can use. you can use following code
[self.navigationController setToolbarHidden:NO];
in the topmost view controller and
[self setToolbarItems:items];
in all your view controllers, where items is an NSArray of that view controller's toolbar items.
select your initial view controller in the storyboard and embed it in navigation controller.
now all your pages should have the navigation bar.. if u manually dragged dropped the previous bars when u run the program it'll show both...
You'll have to remove the old ones and then modify the new one as required.

How to make current view a scrollview? iOS / Objective C

I have a view (that is actually part of a UINavigationControllers view) that i want to make a scrollview.
how do i do that?
could i do something like this:
UIScrollView * content = [[UIScrollView alloc] initWithFrame:self.view.bounds];
self.view = content
(obviously that doesn't work, but is there a way to do it like that)?
Yes, it is, you have to implement delegates, and set the contentSize. The best tutorial on scrollViews ever I found is:
http://www.raywenderlich.com/10518/how-to-use-uiscrollview-to-scroll-and-zoom-content
You are on a good way!
You can create the scroll view programmatically like you do and then add the existing view as a subview of this new scroll view, examine addSubview: (which works on all UIViews and subclasses like UIScrollView as well). I won't say this is the solution or even a clean one for that matter, but if you read about addSubview: you can at least figure out how to have a view live inside a scroll view...

UITableView first row is cut off

What would cause the first row of a table in a nav controller to be positioned so part of it is under the nav controller?
I cannot seem to get it to show the whole row top to bottom; It may seem minor, but it's clearly not correct and I find it unattractive.
TableViewController added to nav controller entirely in code:
SettingsRootController*settings=[[SettingsRootController alloc] initWithStyle:UITableViewStylePlain];
self.settingsView=[[[UINavigationController alloc] initWithRootViewController:settings]autorelease];
[settings release];
SettingsRootController is a subclass of UITableViewController.
It seems that it is a common problem with programmatically-added UINavigationController - see Adding a UINavigationController as a subview of UIView.
Basically, what you should probably do is to set the frame property of UINavigationController before you add it as a subview to anywhere. In the accepted answer to the above question there's also a suggestion to alter the UINavigationController's frame to:
nav.view.frame = CGRectMake(nav.view.frame.origin.x, nav.view.frame.origin.y - 20,
nav.view.frame.size.width, nav.view.frame.size.height);
the only thing that seems to work is manually shifting the table view inside the nav controller down by 10 pixels, but only on iPhone, not on iPad, since there is no alignment problem on iPad and shifting by 10 pixels on iPad creates a gap. this is clearly some sort of nav controller bug, as there are other weird issues noted in other threads.
CGPoint tableorigin=CGPointMake(0,ISIPAD?0:10);

Combined UITableView with other elements - how to create and use the view?

Ive a project close to doing everything I need it to do. Its got a Main page which has four buttons that allow you to choose an option. Then a tableview page is launched from those options and displays a parsed XML feed from a website. You can then select one of the options in the table to see a detail view of the item, enquire about it, etc.
My problem is I need to add more elements to the TableViewController page, other than the tableview itself. I want a customized back button (not the navigation controller standard) plus some labels, images, etc.
In the TableViewController xib, the tableview itself fills the page. I cant resize it to add more elements above it. I can add a 'view' window seemingly above the tableview and put things in it. But it seems to add the view to the tableview. This means that when I scroll the table, the other elements like new back button, scroll away as part of the table.
So I'm led to wonder whether I need this page not to be a tableviewcontroller, but a viewcontroller, with a tableview inside it, as well as my other view with buttons, etc. Is that the right way to go? But if thats the case, then how do I instantiate the tableviewcontroller within code? Because my page will not be of that type anymore - it will be just a viewcontroller. But in code Im making a tableviewcontroller .. slightly scared by that route tbh.
Any illumination on this would be much appreciated, as various searches have left me none the wiser. Thanks.
To customize it, this is the way to go:
Change your class to be a view controller instead, which implements the TableViewDelegate and TableViewData Source protocols.
In the view didLoad of you controller, create the table view, set its delegate, data source, and any other properties you wish and add it as a subview to your view.
tableView = [[[UITableView alloc] init] autorelease];
tableView.delegate = self;
tableView.dataSource = self;
// .. Other customization
[self.view addSubview:tableView];
I suggest doing this programatically rather than IB.
Instead of a UITableViewController, you want a UIViewController that has an IBOutlet UITableView. Drag and drop a UITableView component from Storyboard and hook it up, and position it as needed on the screen. This UIViewController should implement the UITableViewDelegate and UITableViewDataSource methods.
Edit: Remember that a UITableViewController is just a subclass of UIViewController so you don't really have to get rid of all your code. :) You only need to make minor tweaks to your header and main file, and change the Storyboard to be a UIViewController instead of UITableViewController as I mentioned above.

Subviews added programmatically to UIView in storyboards does not responds to action

I have a scroll view with many elements that I had to build as a separate xib because Storyboards graphic interface was clipping it and made me impossible to work with.
The xib is built with interface builder, setting the file's owner graphically to the same view controller allow me to ctrl-click and link between buttons and methods in it.
The view is added like this in the viewDidLoad method:
UIView *w = [[[NSBundle mainBundle] loadNibNamed:#"MainView" owner:self options:nil] objectAtIndex:0];
[self.myView.subviewolder addSubview:w];
where myView is the main view and subviewHolder is UIScrollView the container, both of them are linked to the controller, and the subview get added and display just fine. Self is of course the view controller.
What seems to not responds are the actions in view controller linked to the UIButtons I have in the subviews. I have put some breakpoints but the flow is just not passing there.
What am I missing ?
thanks
The answer was really simple, what I did wrong is to declare subviewholder much more smaller in height than the added subviews.
I thought that subviewholder would act as a placeholder, but instead it was causing the subviews to be displayed correctly but 'clipped' for what concerning the user interaction, therefore the IBAction was never called.