Best practice to develop common header view across all controllers/windows in iOS app

StackOverflow https://stackoverflow.com/questions/20122972

  •  03-08-2022
  •  | 
  •  

Pergunta

I'm keeping on developing an iPhone app (rigth now native one) and I would need to use a common "header" for all views but I don't want/need a UINavigationBar and prefer much more have a common "partial view". It will have some actions to perform but always the same ones (showing notifications panel, basically). It should be something like you can see in the screenshots.

I don't need (I feel) delegation because the controller's view can handle notifications and show them when user clicked the customize button.

I don't mind to use a Nib o make the view hardcoded but I'm not sure how I must make an instance of the view or the controller that handles it within each app tab (I'm using UITabBar as navigation control).

From my point of view it doesn't exist a way to get a common controller to call wherever needed; you just can use some method to present new controller as modal o push it out and I think that is not what I'm looking for.

Any idea is welcome. Thanks

Common header for all views/controllersviews

Main task of header is to show notifications to the customer

enter image description here

Foi útil?

Solução

Create a custom view controller with 2 subviews. Subview 1 is the header. Subview 2 is the container view where child view controllers are displayed (your tab bar controller in this case).

Your custom view controller could be the delegate of the tab bar controller if you want, so it can be notified when the tabs change and update anything on the header view.

Outras dicas

Well, finally is have used the solution I found on the link http://patientprogrammer.wordpress.com/2012/03/12/re-usable-subviews-in-ios/

I have created a Nib with a view controller and then, in the main window I have added two view, the top one subclasses the view controller for the Nib view and it is rendered automatically when app is launched without a single line of code within "main" controller. See the screenshots for more detail:

enter image description here

enter image description here

enter image description here

enter image description here

Thank you very much for your help

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top