How to add button,label and an image to multiple viewcontrollers using tabbarconrtoller - xcode

Im using a tabbarcontroller which leads to 5 viewcontrollers when each tabs selected.
I need to a add button,image and label which are common for all viewcontrollers.Is there any possible way to add these into tabbarconrtoller, so that i don't have to add these to each viewcontroller individually.

You can have a seperate view for your button, image and label, and then add it as a subview in all your view controllers.

Related

Autolayout not working properly

I have UIView in separate .xib file and I make UICollectionView in it.
To add collectionViewCell I made separate .xib file.
Now below collectionview I want to add UIView.but my problem is I set height of collectionview dynamically by using code.
But when I add this using autolayout constraint to add view below bottom of the collectionview but view will add on distance where It put on UI.
I want that first setup collectionview than view placed below it.
Problem screenshot 1
Below UIView constraint I have already set 2
Thanks
Nirav Zalavadia
Instead of adding the UIView below the UICollectionView, place the UIView in the bottom of the screen.
Then, use a constraint from the bottom of the UICollection view to the top of the UIView.

Tabbed view with 3rd view?

I have a tabbed app with two tabs and associated views (two views). One view is a tableview. When a cell is clicked, I'd like to display another view, which will be related to the cell contents.
This introduces a 3rd view that isn't accessed via the tabs. How do I bring in the 3rd view?
I'm guessing drop another viewcontroller onto the story board? But from there, how do I push the 3rd view into visibility upon tableview cell click?
Instead of having one UITabBarController connected to two UIViewControllers, connect your UITabBarController to a UINavigationController and a UIViewController. Put your UITableView inside the UINavigationController as root view controller. When a user taps on a cell, just perform a segue to yet another UIViewController that you push onto the navigation controller's stack.
Something like this:

How to show different views in same window in cocoa?

Is it possible to do navigation within the same window in a mac application ?(Like it is possible in ios apps).I want to show each view in the same window instead of opening different windows on a button click.
e.g When a user clicks a button then the next page should be loaded in the same window.(The next page will have nothing in common with the current page.)
You may use Tab View for easy switching between views on a same window.
UPDATE:
You may also customize your tab view , make it tabless (In the attributes inspector set style to tabless) and use your buttons to switch between views.
You may take help from the following link : http://devcry.heiho.net/2012/01/nstabview-tutorial.html
OR
You may add or remove subviews from your window on button clicks, using
[[yourWindow contentView] addSubview: yourSubview]; // Add subview to window
[yourSubview removeFromSuperview]; //Remove subview
UPDATE:
Steps to swap between views using a tabless tab view.
Drag a NSTabView to your xib.
Set the no. of tabs in attribute inspector to no. of views you want.
Design each view of the tab as per your requirement.
Now in the attribute inspector of tabview, set style to tabless.
Now drag the buttons you want to use for swapping between views. Suppose Button0 and Button1 are for 1st and 2nd view of your tab view.
Create a IBOutlet for your NSTabView in your .h file. Bind it to the referencing outlet of you tabview.
IBOutLet NSTabView* tabview;
Set a IBAction for both your buttons in your .h class file.
In the button action method for button1, use
- (IBAction)button1clicked:(id)sender
{
[tab selectTabViewItemAtIndex:0];
}
Similarly in button2 action method use:
[tab selectTabViewItemAtIndex:1];
In this way you can have any no. of views and you may select any view on button click using
[tab selectTabViewItemAtIndex:(index of the view you want to load)];
In general you want to google for view swapping.
There are tons of examples out there. Some from Apple and lots elsewhere.
Much of it is very similar to iOS.
You need to read the docs a bit too.
Understand NSView and how to load views from nibs, how to create view objects in code, how to add a subview and how to remove a view.
There are many approaches to having different views for different reasons. The right approach is a combination of style, experience and what your app actually needs to do.
Cocoa includes NSBox, NSTabView, and lots of others. Those two can be configured to not display any visual indication that they are containers.
You will also need to understand at least a little about NSWindow to understand its content view (the root container of other views generally)

Xcode Table View sections without using TableViewController

I have a special thing to realize here.
I have a ViewController with a View on it. On the View I have an ImageView (I need a nice Background-Image) and many Buttons and Textfields and so on.
Now I need a Tableview. This Table view is located in the center of the screen.
I need sections in this tableview, so when I edit it to have sections its complaining,
because he wants a TableViewController to use static cells and sections.
Here's the problem. I cant use a TableViewController cause I need this stuff around
the tableview (those buttons and textfields) and I also need the image in the background.
So how can I realize that?
Interface Builder doesn't allow static cells in a table view that's embedded in a view controller. You need to have the table view's datasource point to your UIViewController. The view controller should hardcode the values/configuration for the cells. It's essentially the same thing... you just don't see the results until you run the app.
Also see this question Using static cells in a storyboard UIView with Xcode 4.2

xCode How to programmatically call UITabbar from a tab/subview/subclass using UIButton?

In my UITabbar Application (created using xCode) I have 6 tab buttons.
In the first tab I have 5 UIButttons which should load other 5 corresponding tabs when clicked on the buttons.
First one is the index/home page others are the different modules with a nib file for each of the modules.
My question is when clicked on the Button1 it should load tabbar 1(index's start from 0 for Tabbar App) and when clicked on the Button2 it should load tabbar 2 and so on.
In the IB action I have written the following code
-(IBAction)Button1:(id)sender
{
firstViewController = [[FirstViewController alloc] initWithNibName:#"FirstView"bundle:nil];
[self.view addSubview:firstViewController.view];
}
To the best of my knowledge this paints(adds) the firstViewController on the tabbar 0 instead of calling the tabbar index 1.
Should I try
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;
If so where should I write this?
Create a ParentTabbarController, which will derive from UITabBarController. Now place the subcontroller in this ParentTabBarController. Define a method in ParentTabBarController which will take care of placing the tab view in corresponding tabbar.
From your action on button tap you need to ping the parent controller method with the argument (may be index like 1,2 etc) which will place the tab on the basis of the provided index.
I hope this will help you identify the place to place the above mentioned code.

Resources