How do you add pointsInside:withEvent to xib view? - iphone

I'm just learning iOS programming, so sorry if this is a dumb question.
I have a view in a xib that's acting as an overlay, but I want that view to be "transparent", so that people can manipulate (tap) the views below it. I read that pointsInside:withEvent will do it (if set to return NO), but where do I put this method?
I have a viewController that owns my xib, but putting the method there doesn't do anything...
How do I add my method to a xib view? Do I have to make another view (programmatically) and add my overlay xib as a subview?
Thanks

You can set userInteractionEnabled to NO on the view instead. Overriding pointInside:withEvent: is really for modifying the "shape" of the view.
If you do want to override pointInside:withEvent: you will need to make a UIView subclass and do it there. However you can still add this view inside your xib. Select the view in the xib, and in the Identity Inspector pane set the class to your subclass.

Related

Make self.view a UIScrollView?

I'm experimenting with a TabBarController and the default project creates the UITabBarController and also gives you two view controllers.
I want the view of one of these view controllers to be a UIScrollView, i.e. when calling self.view on FirstViewController I want to get back a UIScrollView * and not just a UIView *.
The view controller gets initialised with initWithNibName: but I can't see anything assigning the view property in there.
If this all sounds a bit weird, maybe I'm doing this wrong? I realise I can drop a UIScrollView onto the view that's already created with me, but it just seemed a bit pointless to have a parent view in this case.
Thanks in advance.
Ok, just realised how to do this.
I can do a cast in my code to make UIView a UIScrollView. Like so...
UIScrollView *tempScrollView = (UIScrollView *)self.view;
tempScrollView.contentSize = self.view.bounds.size;
Then, in Interface Builder, you can use the inspector to set a custom class for your UIView. I set the class as UIScrollView in here and all seems to work!
If you want to use interface builder. Just load up your nib, delete the view on the left panel, and drag a UIScrollView into the area.
Next link from Files Owner to the new UIScrollView as the view property.
The only downside to doing it this way is in your code, whenever you want specific UIScrollView functions you will have to typecast the view property (using (UIScrollView *)self.view ), or put it in a variable like so
UIScrollView *sview = self.view;
//Then use sview for your changes
The best way would be to do it in code however.

Custom iPhone App Tab Bar

Alright, this seems simple enough but I haven't found much documentation or posts regarding this. Basically, I want to have a completely custom tab bar at the bottom of my app. Being new to iPhone dev I thought I could do the following:
Place custom images on bottom of
screen to act as tab buttons.
Create a UIView (lets call it
"ContentView") to fill the rest of
the screen that will display the
appropriate tab's NIB. This
"ContentView" is inside the main
UIView for the NIB.
Hook up image "press" actions to the
controller managing all this.
I'm not sure how I would go about loading the appropriate NIB into the "ContentView" with this method though. From the "Touch Up" action method in the controller can I dynamically load a NIB into that "ContentView" UIView?
Something about this whole thing makes me uneasy.
Is there a better way?
To solve your problem I would create a nib with a UIView and its associated content in it. Connect the nib to a UIViewController. This will be the content of each tab. Create as many of these UIView-UIViewController combination as needed.
When the user touches a tab, create and load the UIViewController from the nib using
– initWithNibName:bundle:
Add the UIView in the nib to the main content view as a subview. Use
– addSubview:
As the user presses other tabs load the other nibs into memory and add their UIView into the main content view as a subview.
If a view is already in memory you can show and hide subviews with the following methods.
– bringSubviewToFront:
– sendSubviewToBack:
I think that would work.
You can solve this by,
either make different views with same tab bar image and custom button(load view on IBAction for button click:toucp up inside) or you can make different views for the same view(so you can hide views and show only one view at a time accordingly).
and you can load view (if you app is view based then add other views on window otherwise for navigation based app you need to pushViewController of navigation controller.
This is a tricky task but you need to handle this.

Design view in Interface Builder to load lazily in UIViewController

I've managed to get my myself confused... I've got a fairly complex View Controller much of which is developed programatically. I'd like to pop up a "dialog" on top of the view controller at some point and I'd like to "design" that view in Interface Builder because it's fairly straightforward (background UIImageView, some UILabels and a UIButton).
I've created the .xib and am now subclassing UIView with the IBOutlets,etc. I'm now trying to wire it up and realizing I probably need to add an initWithNibName: method so this will instantiate correctly...then I realize that I'm really just making another UIViewController and I don't think we're supposed to have UIViewController views w/in other UIViewController views?!?
So now I'm re-thinking how to go about this "correctly." How best to use IB to design a simple 1/4 screen view that will pop up over a main view?
Call +[NSBundle loadNibNamed:owner:] to load the NIB file that contains your view. If you specify your view controller (i.e., self) as the owner, any connections you make to File's Owner in the NIB file will then be made to the view controller. So you could declare an outlet to your custom view in the view controller and after the call
[NSBundle loadNibNamed:#"MyView" owner:self];
the outlet variable will point to the view object. Alternatively, you can use -[NSBundle loadNibNamed:owner:options:], which returns an array of the top-level objects in the NIB.

Why won't my UITableView rotate?

Within Interface Builder, I have the following
UIViewController
-- View
---- TableView
In my UIViewController I have set
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
I also have other view controllers that are in IB. What am I missing here? The only way I can get it to rotate is if I use the transform method.
Are you using the tableview in a tab-based app by any chance? In case you are, you can only get a view to support landscape mode if all the viewcontrollers of the tabbar controller support landscape mode.
Other than that, I don't see any reason why your view should not support landscape mode.
The problem is with the autosizing settings. To be more specific, in Interface Builder, make sure autoresizing is clicked, then in the Size Inspector, make sure the tableview all it's superviews of the table view have red arrows filled in on the top, left, right, and also select the two internal arrows.
I am wondering if the questioner actually had the table view in a subview of the main view. I see this behavior for a table view that is one level deeper in the view hierarchy:
Main View
Subview
Table View
By default, the Main View has it's autosizing arrows set up correctly, but if you add an additional view, it does not.
In response to the question about the problem being with multiple view controllers: Note that a UIViewController is not a UIView's delegate. In fact, it looks like chain of events goes the other way - first the system sees an autorotation and tells the UIViewControllers about it. If the UIViewControllers have shouldAutoresize returning yes, then the UIViewControllers resize their main views. The resizing of the main views can automatically cause their subviews to resize if they are set correctly.
According to Apple docs, you should not have multiple view controllers controlling different parts of a view - for example a separate tableview controller for a table view that is in a subview of the main view - because it mucks with the event chain - you could see how that would be the case here. Don't know if that's helpful or not.
I just tried this, and it works as expected. You will need to provide more detail, I think. In my experience, when a view "fails" to rotate, that's because some view controller somewhere is telling it not to. Check to make sure all your view controllers are returning the right values from shouldAutorotateToInterfaceOrientation:
if your are using storyboard, your VC contains a UITableview, check if your Scene have AutoLayout unchecked.

Possible to initialize an entire UITableViewController (or subclass) from a secondary NIB... not just a UIView?

Nearly all the UINavigationController examples out there show the use of initWithNibName:bundle: to load a NIB containing NOT an entire UIViewController (or subclass) but just a UIView, with the NIB's File's Owner Class property set to UIViewController (or the appropriate subclass) and its view outlet pointed at the UIView.
Why is this? Why can you not instantiate a full UIViewController (in particular, a UITableViewController) from a secondary NIB? And why do you even need to set the view outlet in IB? I don't understand the point of creating a blank white view which is going to be entirely ignored by a UITableViewController anyway.
In the MainWindow NIB, you can do both of the things that you seemingly can't do from a secondary NIB. You can setup a UINavigationController, and then within that you can setup a UITableViewController (or subclass). And you don't need to create an entirely superflous UIView object - rather helpful, since the whole point (I thought!) of a UITableViewController is that it creates and manages an associated table view for you using its delegate methods.
What is going on here? Am I being stupid? Is there some other way of doing what I want to? Or is there some logical reason for things being the way they are?
In IB create a new "Empty" nib and drag a "Table View Controller" into it from the Library.
Or am I misunderstanding the question?