I want to add UIView below UINavigation bar on each screen. I don't want to add it on every viewcontroller explicitly. I want to add a view in parent class so that the rest of the views in every viewcontroller starts below the view that I added below UINavigationBar. Currently, I have added a view in parent class but it appears over the views in child classes. Any solution?
Here it is i got one very nice helpful github project for show a custom message view under thenavigation bar here is link TSMessages
Make your custom UIView in xib and use inheritance concept. Create a BaseViewController and all other view controller should be subclass of your BaseViewController. Load your custom UIView in BaseViewController it will be there all other subclasses
Related
I've been trying to add a custom class named ThirdViewController to My TableView controller which is a third tab of my Tab Bar Controller. When i try to use a View Coontroller it displays but for table View controller which is required, it doesnt show any suggestion in my custom class.PFB the image for the same. Image here
You can simply try creating UIViewController class and then use UITableView in that view controller
I want to make custom tab bar. And I'm using framework of KittenYang
Here is everything is very beautiful, animated but I don't know how to add View Controller for showing. Thanks for any helps)
You do not need to add an integrated ViewControllerclass to your project, what you need to do instead is to add TabbarMenu class instance to your desired UIViewController subclass and add it as a subview to UIViewController's view.
I have a custom uiscrollview class that has certain views and buttons. When I press a button in this custom scrollview, I want to present a new viewcontroller. Since this scroll view is inside of a view controller, and the custom class doesn't have the authority to push view controllers like a navigation controller, how do I push a new view controller through this uiscrollview class without throwing an error? Whenever I create a new navigationcontroller and an instance of the viewcontroller that I want inside of the method for when the button is pressed, and I present that viewcontroller, I get an error. Also, all of this is programatic and dynamic, not though storyboard. Thanks.
The scrollView must be inside a viewController.
The best way to accomplish your scenario is to put the viewController that contains the scroller inside a navigationController, Then you can push to wharever you want.
Hope this may help
You can try to instantiate viewController through the storyboard, or directly from class, after that present it as a modal view controller from your source UIViewController like this
presentViewController:animated:
This possible leads to animation issues, that could be solved implementing your own animation
In my app, I have to show same NavigationBar for all UIViewControllers. This NavigationBar has three buttons and these three buttons which will be act as TabBar functionality, that is each tab has its own stack cycle. I have created custom view for NavigationBar with three buttons, but after adding this custom view to HomeViewController, I have to manually add this custom view for all other view controllers. I don't want to do this.
Is there any simple method to achieve this?
There are a couple of ideas that come to mind. First of all, you could use view controller containment and actually have 1 controller that implements your custom nav bar, and then swap out the contained controller as necessary.
If that's not feasible, you can simply use inheritance and have all your custom controllers inherit from a controller that has the nav bar in place.
Another option could be to write your own UINavigationController subclass. I'm not certain if you can override the UNavigationItem behavior, but if you can, you can just just do that -- instead of the UINavigationController taking its child's UINavigationItem to update its own UINavigationBar, the UINavigationBar perhaps just stays the same, like you're expecting/hoping.
I have some static cells that I want to display, so I have a UITableViewController. There is also a NavigationBar in this scene that contains some buttons at the top. The setup looks like this:
If I had a UIViewController that contained a UITableView in it, the setup would look like:
So, the question is:
Why does the Navigation Bar have to be embedded inside the UITableView when using a UITableViewController? (I have tried putting it elsewhere but IB won't let me)
I know that UITableView is a subclass of UIView, but is it OK that the top level element in the hierarchy is not a View (but a TableView)?
Thanks.
You shouldn't be placing your UINavigationBar in your UITableView. You should be putting your UITableViewController in a UINavigationController, because that will provide a UINavigationBar for you.
So if you select your UITableViewController in the storyboard, you can choose Embed In -> Navigation Controller from the Editor menu. This would be the proper way to do it.
There are two ways to use a UINavigationBar in iOS:
Embedded inside a UINavigationController (recommended)
As a standalone object
For your particular situation, I'd recommend that you put your UITableViewController as the rootViewController of a UINavigationController. That way you automatically get a navigation bar which you can customize according to your needs. In a typical user experience, when you tap some of your table view rows a new view controller will be pushed onto the navigation stack, so you'll probably end up needing a navigation controller anyway.
What if you decide to use a navigation bar as a standalone object? This is perfectly fine, you can use it inside a view hierarchy as an ordinary UIView, but you'll need to create another object that implements the UINavigationBarDelegate protocol and set it as the delegate property of your navigation bar. If you use a UINavigationController the delegate is already set and configured for you. You also need to add/remove navigation items (instances of UINavigationItem) to your navigation bar by using the pushNavigationItem:animated: and popNavigationItemAnimated: methods.
And about your question on the view hierarchy, you can use a UITableView anywhere a UIView is required. The only caveat is that a UITableView is a view hierarchy on its own and that may restrict your layout a little bit.
The way a UITableViewController works, is its root view is a UITableView. So there is no way to put the UINavigationBar anywhere other than in the UITableView.
I tend never to use a UITableViewController as it doesn't really give you much.
If you particularly want to use the UITableViewController, I don't believe that there is any real problem in having the navigation bar within the table view. You just need to make sure that you set the contentInset on the table view such that the navigation bar doesn't block the content. Though it seems a bit backward to do it this way.
My recommendation would be to just use a normal UIViewController with a navigation bar and a table view.
If you actually need functional navigation, you need to put your UITableViewController within a UINavigationController.
Hope this helps :)
Let me know if anything is still unclear.