cornell-dti / Rescuer

Mobile app to enhance campus safety for the Cornell community
https://itunes.apple.com/us/app/cornell-rescuer/id1209164387?mt=8
1 stars 1 forks source link

About titles for tab bar item #1

Closed MinionKel closed 7 years ago

MinionKel commented 7 years ago

I played with your app and it was amazing. Much better than the project I wrote lol... I do have some suggestions though.

I saw that you set names and icons for tabBarItem in your AppDelegate.swift:

home.tabBarItem = UITabBarItem(title: "Home", image: UIImage(named: "home"), tag: 1)
guide.tabBarItem = UITabBarItem(title: "Guide", image: UIImage(named: "guide"), tag: 2)
settings.tabBarItem = UITabBarItem(title: "Settings", image: UIImage(named: "settings"), tag: 3)

but clicking tab item will change the name to 'Cornell Rescuer' and 'Emergency Guide'. The problem is that you have title='xxxx' in your view controller's viewDidLoad() method and it will overwrite the title you set when you initializing view controllers in AppDelegate. Try to remove either of them.

If you want to have tab bar item displaying 'Home' and 'Guide', with their navigation bar displaying 'Cornell Rescuer' and 'Emergency Guide', I would suggest you to do as followings:

  1. Move this piece of code

    home.tabBarItem = UITabBarItem(title: "Home", image: UIImage(named: "home"), tag: 1)
    guide.tabBarItem = UITabBarItem(title: "Guide", image: UIImage(named: "guide"), tag: 2)
    settings.tabBarItem = UITabBarItem(title: "Settings", image: UIImage(named: "settings"), tag: 3)

    into their view controllers' viewDidLoad() method. This step is not necessary but I strongly recommend you to do so because I think handle tarBarItem in their view controllers would make your code clean.

  2. In your view controllers. Take MainTableViewController.swift for example. In viewDidLoad() method, the order you set each property should be:

    self.title = "Cornell Rescuer" // This step could be omitted
    self.tabBarItem = UITabBarItem(title: "Home", image: UIImage(named: "home"), tag: 1)
    self.navigationItem.title = "Cornell Rescuer"

    Then you will have 'Home' in your tab bar but 'Cornell Rescuer' in your navigation bar. I guess that's the way you want right? Make sure you set title at the beginning because setting it will overwrite titles in tab bar and navigation bar.

=============================================

If I understand it correctly, in your most recent commit 'trying and failing to resolve back button issue for maddening reasons', are you trying to change the title of back button to 'Guide'? If so, you may consider doing it this way: in your MainGuideViewController.swift, add two lines of code to the method tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath):

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let guideDetailViewController = CollapsibleTableViewController()
        guideDetailViewController.value = GuideText(topics[indexPath.row]).value
        guideDetailViewController.title = topics[indexPath.row]
        let backButton = UIBarButtonItem(title: "Guide", style:.plain, target: nil, action: nil) // new line
        self.navigationItem.backBarButtonItem = backButton // new line
        print(navigationItem.backBarButtonItem)
        navigationController?.pushViewController(guideDetailViewController, animated: true)
        tableView.deselectRow(at: indexPath, animated: true)
    }

The back button should have title 'Guide' now.

The concept should be correct but I didn't test the code so I cannot guarantee anything..

If I understand your problems wrong... just ignore me because I am just jabbering...

mattbarker016 commented 7 years ago

Thanks for the help! We fixed the stuff before release