How to change titleview of a navigation item inside Tab Bar controller? - uitabbarcontroller

So I have created a UITabBarController as my root controller, then added UINavigationController as a tab bar item, and a UIViewController as a navigation item for it.
I want to set an image instead of the navigation item title, so I tried the following in viewDidLoad in the UIViewController, but it didn't work:
UIImage *image = [UIImage imageNamed:#"logo.png"];
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:image];
Any Suggestions?
Sorry for my poor English.

Well guys, I have found out what went wrong!
I should have set the class property for the UIViewController to my custom class controller, that's why viewDidLoad was not being called.
Just follow this tutorial here, and everything should be fine.
http://www.youtube.com/watch?v=LBnPfAtswgw
Now, I want to push another view from the navigation controller?

Related

Swiftui - Cannot present Form inside Sheet or FullScreenCover

When using a Form on a view and presenting it with either .sheet or .fullScreenCover the view is never presented and instead memory is quickly gobbled until the app crashes. Removing the form and replacing it with anything else works just fine.
Inside top level view, the sheet or full screen uses:
.fullScreenCover(isPresented: $showProfile, content: {
NavigationView {
ProfileNumberView()
}
})
OR
.sheet(isPresented: $showProfile, content: {
NavigationView {
ProfileNumberView()
}
})
The view it's launching can be as simple as:
var body: some View {
Form {
Text("TEST")
}
}
Again doing this causes the app to simply gobble up memory until a crash and no view is presented. If I simply remove the Form tag, the the view will present as normal. I have also tried embedding the NavigationView inside the form view (above the Form tag) but to no avail.
Why can I not present a view using a Form in this manner?
Update: I have discovered the source of the issue is when the top level view contains a List. If there is no list the screens present just fine, but it seems we cannot present a form within a cover or sheet if the parent has a list in it. Still not clear why that would be the case but commenting out the list and the sheet or fullscreencover worked.
The turned out to be something that was not directly related to the code I posted above. It's worth posting the answer though as I am sure others may run into this. The problem was styling given to the list in order to paint a background with an image. Specifically:
UITableViewCell.appearance().backgroundColor = .clear
let imageView = UIImageView(image: UIImage(named: "gradientBackground"))
imageView.contentMode = .scaleToFill
UITableView.appearance().backgroundView = imageView
This styling of the list for some reason prevents you from presenting a sheet or full screen cover that has a form. Very unclear why and I need this background, so while this particular issue is resolved, the functionality required is not.

How to create a navigation stack of views in SwiftUI?

In UIKit it is possible to create a navigation view controller with a stack of UViewControllers.
let nav = UINavigationController()
nav.viewControllers = [vc1, vc2, vc3]
How would you achieve same in SwiftUI?
There are navigation buttons that push a view but there is no navigation controller

How to add a right button when specific UIViewController get loaded in Swift 3

I have two different UIStorboards and I am using a UINavigationController to load the pages.
I have a total of three UIViewControllers. Two of them are on the first UIStoryboard and the third one is on the second UIStoryboard.
1) Navigation controller
2) Main Controller
3) Value Screen Controller.
I want to add right button on navigation bar only when value screen controller get loaded. It should not be available on Main view controller.
I tried with this solution but not worked.
Each UIViewController has its own UINavigationItems. So you can just add this right button in your Value Screen Controller by adding this line:
self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: <#T##UIBarButtonSystemItem#>, target: <#T##Any?#>, action: <#T##Selector?#>)
You can place it in func viewDidLoad() if you want it to be place as soon as the UIViewController's view is loaded.

Navigation Bar Background Color Light with Swift 3

I add Navigation Bar in any view controller. But, I'm adding new CollectionView Controller in project. My problem is that I could not add Navigation Bar in Collection View Controller.
So I add Navigation Bar with code. I choose Top Bar- "Inferred" in Attributes Inspector. Here is the code.
//Add Navigation Bar
let height: CGFloat = 65
let navbar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: height))
navbar.delegate = self
UINavigationBar.appearance().barTintColor = UIColor(red: 0.0/255.0, green:49.0/255.0, blue:79.0/255.0, alpha:0.1)
UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().isTranslucent = true
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white]
But, the Navigation Bar Background Color in Collection View Controller is a little bit dark than other view controller.
In other view controller, I drag and put navigation bar.
- Navigation Bar style --> Black
- Translucent --> not enabled
- Bar Tint Color --> #00314F
I don't know why Navigation Bar Background Color in Collection View Controller is light than in Collection View Controller.
Please help me how to match Navigation Bar Background Color in all view controller.
If it is not easy to do, is there any ways to add Navigation Bar in CollectionViewController without embedded in Navigation Controller and without code.
It is beacause of the Translucent property of NavigationBar. It gives an effect where the image color looks faded as if a layer has been put on the bar, hence the color looks a little and different. Set off the translucent property of navigation bar as shown below. You can write this code in any lifecycle methods.
self.navigationController?.navigationBar.isTranslucent = false
It is because of translucent i think. When the navigation bar is not translucent, view can't locate behind the navigation bar to show what it has. But when is translucent, view stays behind the navigation bar and with view's color, you see it darker.

UITabBar item did select is not working

i have two tab bar items with two different table view with navigation controllers.
by clicking on the tab1--- table1 is opening...Good. but when i did select on table1 it goes to the another view (table did select view)....every thing is good.
but the problem here is
when i am clicking on tab2 ----table 2 is opening....Good.
But again clicking on tab1------ it is not loading the table1....it is loading (table did select view) view. As the last time i left it there.
i want to open table1----on clicking on tab1......by programming.
help me
That is the expected behaviour if you are using the tab bar controller and the navigation controller in the item of the tab bar. User will expect the tab to retain the state of the view.
If you still want to enforce the app to go back to the root view controller of the navigation controller when user goes back to the tab, you can implement the UITabBarControllerDelegate tabBarController:didSelectViewController: method. What this delegate method does is:
Tells the delegate that the user selected an item in the tab bar.
Then call the method of UINavigationController called popToRootViewControllerAnimated: when user tap on the tab. This will help you to:
Pops all the view controllers on the stack except the root view
controller and updates the display.
For example:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if(viewController == yourNavigationController) {
UINavigationController *navigationController = (UINavigationController *)viewController;
[navigationController popToRootViewControllerAnimated:NO];
}
}