iAd in Tab bar application - ios

How to add iAd below the Tab bar, I have added tab bar in rootviewcontroller
self.window.rootViewController = tabBarController;
For a any single view controller adding iAd in viewController by
[self.contentView addSubview:viewController1.view];
[self.view addSubview:contentView];
[self.view addSubview:adBannerView];
is working , but the code for tab bar controller
[self.contentView addSubview:tabBarcontroller.view];
[self.view addSubview:contentView];
the tab bar controller not loaded,
How to add this, thanks in adv

The best is that you follow the pattern described in iAD suite (a sample code on Apple site). the best advantage that you get is that you don't lost the banner while changing view controller. The idea is that you have an instance of a BannaerManager that shares its iAD banner with a visible BannerViewController that is a container for you VC.

Solved by,created a seperate view controller similar to mentioned in Example iAdsuit
Try to pass your tab bar controller to banner view controller by
self.window.rootViewController = [[BannerViewController alloc]initWithContentViewController:tabBarController];

If you want the banner to persist between the tabs and not disappear when rapidly switching tabs, you've got to do the iAd Suite approach: http://developer.apple.com/library/ios/#samplecode/iAdSuite/Introduction/Intro.html
Moreover, you have to have a relationship segue from your tab bar controller to a View Controller that has container view embedded into it. Do that in your storyboard. Also, you need to set Custom Class to BannerViewController for each tab, and embed your content into the embedded view. Take a look at this post for details on how to do it it the Storyboard: https://stackoverflow.com/a/16205420/5007500
If you are not using Storyboard - you need to set BannerViewController as parent view controller for each of your tabs.

Related

Is there a way to change only part of the layout when button is clicked in container view?

I'm new to iOS development using Swift. How can I change just the bottom layout with a container view so that, when Button A is clicked, the button layout changes and shows the "A" detail page, while the top layout still exists, like in this image:
When you are working on this kind implementation there is so much responsibility for your view controller have to handle. In place of adding many responsibilities to one view controller, you can distribute the responsibility to multiple controllers. To achieve this add container view at the bottom and add navigation controller as a subview.
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:storyBoardName bundle:nil];
UINavigationController *navigationViewController = [mainstoryboard
instantiateViewControllerWithIdentifier:#"navigationController"];
// place navigation controller inside content view
[self addChildViewController:navigationViewController];
navigationViewController.view.frame = self.containerView.bounds;
[self.containerView addSubview:navigationViewController.view];
[navigationViewController didMoveToParentViewController:self];
Hope this will help.
Place a container view as bottom view. Embed the view controller of the container view in navigation controller. This will allow you to go to detail page and move backwards.
I have implemented this in a sample project. Download the sample project from my Github Repo
Note: BarTint of navigation bar is white (navigation controller)
Let me know if you need any help.
See the sample execution.

Safe way to remove tab bar from UITabBarController in ios

I want to use UITabBarController but I do not need a tab bar because I'm going to switch tabs from the menu in another view controller. I want to remove it as it will be never used. I've created a subclass of UITabBarController and put this code:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tabBar removeFromSuperview];
}
Is that safe to remove tab bar that way?
Update: Why tab bar controller?
Apple suggests to use standard container view controllers whenever it possible. I'm trying to follow that. My screens workflow is the same as for tabs, except that they are switched by left side menu, not by the tab bar.
When I use a UIViewController and change it's child view controller I've got a lot of problems when autolayouts are not working properly.
The other reason is that I want to use story board, rather then create segues from the code so I can see my app workflow easily.
When you are saying, you don't want to use it, then why to remove it. You can go with a
tabbarcontroller with hidden tabbar. I am switching tabs from the bottom custom bar.
I am doing an app, which has a tababr controller with three items. Instead of using system tab, I am creating a custom view at the footer like tab & have actually set the hidden property of tabbarController's tabbar to YES.
myTabBarController.tabBar.hidden = YES;
Try this code
[app.navigationController.view removeFromSuperview];
[app.tabbarcontroller.view removeFromSuperview];
[app.window addSubview:app.navigationController.view];
[app.navigationController popToRootViewControllerAnimated:YES];

TabBarController - switch tab keeping banner view;

I have a TabBarController with four view controllers . In my first view controller i have the following two methods:
-(void)loadclistview
{
[self.tabBarController setSelectedIndex:2];
}
-(void)loadglistview
{
[self.tabBarController setSelectedIndex:1];
}
I use them to change the view form one tab to the other. But changing tabs this way doesn't preserve my banner view, it does not load the banner into the new view controllers (tabs). If i change tabs using the tab bar , all the views load banners correctly.
Pls help me here - i don't know why this is happening , and what should i do to switch tabs through selectors so that the banner will load in the new views.
EDIT:
I solved it by adding the current bannerview as a subview to the selected viewcontroller from the tab bar ; like this:
[self.tabBarController.selectedViewController.view addSubview:_bannerView];
I saw this also works to adding the bannerview to subsequent view to a navigationcontroller - like showing the banner in child views of the main view which constitues a tab;
[self.navigationController.view addSubview:_bannerView];
Adding the subview this way is fine, but you also have to handle the show/hide of it when there is or isn't an iAd, and the resize of the content view to make room for displaying the subview. The TabbedBanner project in the Apple iAdSuite sample has a nice encapsulation of this functionality.

UINavigationController isn't pushing/displaying view

New to iOS and objective C. Trouble with custom UINavigationController while developing an iPad app in XCode simulator. Appreciate your help greatly !
Created project (view based application) in XCode. Application currently has two views. Home Page and a Detail View. Want a Home Page like Facebook or Linkedin iPhone App Home page...where you have bunch of icons/images on the home page, and click on each to get more details
(With limited knowledge) concluded Home page can't be TableView, SplitView or TabBarView. Don't want any tabs or table view style in Home page (as explained above). So couldn't start XCode project with "Navigation Based Application" template
Didn't add UI elements from IB to MainWindow.xib, rathar homepage UI elements are in the otherView.xib created by the project template. The project template, assigns rootViewController to otherViewController within appDelegate.didFinishLaunchingWithOptions method. self.window.rootViewController = otherViewController.
Added a NavigationController through IB to otherView.xib. Added outlet for navigationController. otherView.h has following
UINavigationController *navigationController;
#property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
referencingOutlet for navigationController is connected to File's Owner
When App is launched Home Page (served by otherViewController) comes up. When clicking on an icon in Homepage (an ImageView with Button behind), Detail View doesn't show up, if I call
[self.navigationController pushViewController:DetailViewController animated:YES];
(within the action method, that's handling touchUpInside for that button.)
but detail view shows up if I do either
self.view = DetailViewController.view;
or
[self.view addSubview:DetailViewController.view];
So doesn't seem to be a problem with DetailView loading it's nibfile etc.
No problem also in button click/touch event capture etc.
A. When I examine the navigationcontroller in the debugger, it has both the two viewControllers in its stack, with rootView/ Home page at index 0, and Detail View at index 1. navigationController is not null. Any ideas on what am I missing ?
B. Do I need to add a navigationBar to both the home page (in whose view navigation controller is added) and the detail view ? I have added a navigationBar to the detail view. I don't need a navigation bar in the home page UI.
C. When the detail view shows up through the addSubview call or self.view assignment (as mentioned above), the navigationBar doesn't show the back button (which should say "Home").
Both view Controller is setting appropriate title , using self.Title = "Home" or "Detail".
Appreciate your help. Thanks
In the appDelegate, you need to make navigation controller a property and then write:
self.window.rootViewController = self.navigationController;
in application didFinishLaunchingWithOptions: method.
Then push otherViewController onto its stack. I think the mistake you're making is adding UINavigationController to UIView instead of the other way around, which is the correct way!
what you should do too in your xib file,
make sur that you view is in a navigationcontroller
the tree of your xib file should like this :
your appdelegate
window
navigation Controller
navigation bar
and your rootviewcontroller

uinavigation not working

My navigation controller not working.
I take a tabbar-based application now from app delegate. I want to add a navigationcontroller but it's not working.
[window addSubview:navigationController.view];
I simply make an object of uinavigation controller and synthesize it.
Actually you don't need to add navigation Controller's view in the window, if you want to add a navigation controller in tabbar controller application.
See the below screen shot, you just need to select the tabbarcontroller in the IB and then from inspector window you can select class or particular tab item. Just make then navigation controller.
Open MainWindow.xib.
Under TabBarController you will see two view controllers.
Delete both of the view controllers.
Now, from the library add two navigation controllers under TabBatController.
Now, open the inspector of the navigation controller and set its nib name and the class name.
i think this will solve your problem.
You can also go through
http://21gingerman.wordpress.com/2009/04/06/tutorial-and-sample-code-for-iphone-app-with-tab-bar-and-nav-bar/

Resources