Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DennisBlah

macrumors 6502
Original poster
Dec 5, 2013
485
2
The Netherlands
Hi all,

I'm making some apps lately and I'm facing some issue's while navigation through views with consistency of my 'views'.

On all my views I make a UIView that contains my buttons.. and a UIView that acts like an 'header' with an image and some title bottom right just below the image.

Is there an way to make these 'header' and 'footer' in an UIViewController class, and load these INSIDE another view ?

So where I want to go is, making this 'header' and 'footer' once so I can include these in my views.

The reason I'm doing it like this is, the default Navigationcontroller class is too short for my image, and adjusting it with code is just ... not simple enough for quick editing.

AND I just don't seem how to include an 'footer' in my controller so my other viewcontrollers will be between the header and footer.

Hopefully someone can help me out here, with an sample or an tutorial ?

I been looking around but.. it just does not make sense to me.

Thanks!
 
Last edited:
I would consider making your baseViewController and set up the footer and header views exactly how you want them. In the baseViewController I would probably place an empty center view that would contain the content that is different on each screen. Expose the contentView as a property.

Then all your other viewControllers would be a subclass of baseViewController. Then all your subclass viewControllers could assign that centerView with their custom content and you have to touch the header and footer views.
 
I would consider making your baseViewController and set up the footer and header views exactly how you want them. In the baseViewController I would probably place an empty center view that would contain the content that is different on each screen. Expose the contentView as a property.

Then all your other viewControllers would be a subclass of baseViewController. Then all your subclass viewControllers could assign that centerView with their custom content and you have to touch the header and footer views.

That is exactly what I'm trying to do, however I can't get the other viewcontrollers a 'sub' into the base.
How do I do this, and how can I then navigate from one 'sub viewcontroller' to another and still keep the baseview ?


It's not an toolbar, it's a view with custom icons and background which will be changed based on the settings on the database on the web.
Same thing for the 'header'.

I can get the header size bigger like:
Code:
//Resize navigationBar
    self.navigationBar.frame = CGRectMake(0,0,self.view.frame.size.width, 150);
//Load background header
    UIImage *image = [UIImage imageNamed:[mySettings objectForKey: @"headerBG"]];
    UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
    imgView.frame = CGRectMake(0,0,self.navigationBar.frame.size.width,self.navigationBar.frame.size.height);
    [self.navigationBar addSubview:imgView];
//Load header image
    image = [UIImage imageNamed:[mySettings objectForKey: @"header"]];
    imgView = [[UIImageView alloc] initWithImage:image];
    imgView.frame = CGRectMake((self.navigationBar.frame.size.width / 2) - 90,0,180,150);
    [self.navigationBar addSubview:imgView];

From there I can navigate through the app and reserve the size and background by calling it in the 'navigationviewcontroller' viewdidappear, because it's being resetted everytime. However this is giving a little glitch when rotating my orientation.

Any help would be appriciated
 
Are you using Storyboards? If so you can create a prototype cell and then use that cell's view as the header/footer. It isn't the most efficient way, but it gets the job done and works fantastic. It is my typical go to for a quick and dirty solution.

See: http://stackoverflow.com/questions/...w-section-headers-and-footers-with-storyboard

I will read through this later tonight.
But actually I want to use navigationcontroller
So my header and footer will be initialised once and setup once.
Like html and iframe
A html page, with header, iframe, footer
And everything gets loaded in the iframe without reloading the header and footer
 
That is exactly what I'm trying to do, however I can't get the other viewcontrollers a 'sub' into the base.
How do I do this, and how can I then navigate from one 'sub viewcontroller' to another and still keep the baseview ?
You never directly I itialize the base controller. When you create your firstContoller it is if type BaseViewCintroller not UIViewcontroller. Then you make secondView controller also a subclass of baseViewController and switch between them like normal.

all the properties that you want shared between all your views get added to the base controller and unique stuff gets added in your subclasses.
 
Hi all,

I been playing around, googling around and throwing codes around up and down.

I now got 1 'rootViewController' where I build up my 'template'.
In here I set an 'containerView'.

With seque's and a seque UIStoryboardSeque object, I now load other viewcontrollers in the containerview :D

Thanks for everything all!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.