RNBlurModalView for displaying UIView - iphone

i'm recently find this awesome modal view popover (source).
"Usage" section there is telling how to show RNBlurModalView with UIView in it with following code:
RNBlurModalView *modal = [[RNBlurModalView alloc] initWithViewController:self view:view];
[modal show];
Everything works fine when i'm using RNBlurModalView to show custom UIView like square with following code:
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 200)];
view.backgroundColor = [UIColor redColor];
view.layer.cornerRadius = 5.f;
view.layer.borderColor = [UIColor blackColor].CGColor;
view.layer.borderWidth = 5.f;
RNBlurModalView *modal = [[RNBlurModalView alloc] initWithViewController:self view:view];
[modal show];
, but i'm having problem when i'm trying to show UIView from UIViewController in RNBlurModalView, it just shows empty modal view, here's code that i'm using:
ExampleViewContoller *exampleVC = [[ExampleViewContoller alloc]init];
RNBlurModalView *modal = [[RNBlurModalView alloc] initWithViewController:self view:exampleVC.view];
[modal show];
Here is image of ExampleViewController from storyboard if needed -
Question : any ideas what am i doing wrong, why modal view is empty?

Well the problem is with which you are calling for viewcontrollers view .
Try this
UIStoryboard *storyBoard=[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle mainBundle]];
ExampleViewContoller *exampleVC = [storyBoard instantiateViewControllerWithIdentifier:#"ExampleViewContoller"];;
RNBlurModalView *modal = [[RNBlurModalView alloc] initWithViewController:self view:exampleVC.view];
[modal show];
Note dont forget to set the storyboardId of the ExampleViewContoller as "ExampleViewContoller"in the storyboard.

Related

Creating TabBar programmatically only for one ViewController not in AppDelegate

I want to create a tabBar in my app but only in a detailView not in the AppDelegate. I am searching how to do this in google but everything what I have figured out is in AppDelegate.m
I am trying to do something like this. This shows me a Tab bar with two buttons(without names) but I want to go from one FirstViewController with tabBar, to one of the two items SecondViewController or ThirdViewController with a navigationBar with one backItemButton for get back to the FirstViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self setupTabBar];
}
- (void) setupTabBar {
tabBars = [[UITabBarController alloc] init];
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:4];
YPProfileViewController *profile = [[YPProfileViewController alloc] init];
YPProfileViewController *profile2 = [[YPProfileViewController alloc] init];
[localViewControllersArray addObject:profile];
[localViewControllersArray addObject:profile2];
tabBars.tabBarItem = profile2;
tabBars.viewControllers = localViewControllersArray;
tabBars.view.autoresizingMask==(UIViewAutoresizingFlexibleHeight);
[self.view addSubview:tabBars.view];
}
at least this works for me.
UIViewController *vc1 = [[UIViewController alloc] init];
vc1.title = #"FIRST";
vc1.view.backgroundColor = [UIColor blueColor];
UIViewController *vc2 = [[UIViewController alloc] init];
vc2.title = #"SECOND";
vc2.view.backgroundColor = [UIColor redColor];
UITabBarController *tabBar = [[UITabBarController alloc] init];
tabBar.viewControllers = #[vc1,vc2];
tabBar.selectedIndex = 1;
tabBar.view.frame = CGRectMake(50, 50, 220, 320);
[tabBar willMoveToParentViewController:self];
[self.view addSubview:tabBar.view];
[self addChildViewController:tabBar];
[tabBar didMoveToParentViewController:self];

Show iAdBanner on top of nav bar

i want to show iAd Banner on top of Nav Bar.
I tried with the following code
Devanagari *viewController = [[Devanagari alloc]init];
viewController.delegate = self;
// _adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, 0, 320,40)];
_adView.frame = CGRectOffset(_adView.frame, 0, -50);
_adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50];
_adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
_adView.delegate=self;
self.bannerIsVisible=YES;
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:viewController];
navigationController.navigationBar.tintColor = [UIColor brownColor];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
didn't worked.
Is there any way that i can show iAdBanner View on top of the view and then right below nav bar.
Thanks for help.

Why is UISearchBar not shown correctly?

In order to understand how UISearchDisplayController works i've written the following code in viewDidLoad method:
UISearchBar * searchBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 40.0f)] autorelease];
searchBar.delegate = self;
searchBar.showsCancelButton = YES;
_searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
_searchController.delegate = self;
_searchController.searchResultsDataSource = self;
_searchController.searchResultsDelegate = self;
[_searchController setActive:YES animated:YES];
[_searchController.searchBar becomeFirstResponder];
But when i run my code the UISearchBar doesn't being shown as you can see in the image.
You create UISearchBarcontroller its good but not added in uiviewcontroller. So You add UISearchBarcontroller in uiviewcontroller.
coding:
[self.view addsubview:_searchController];

NavigationController not showing on UIViewController presenting modally

Have a mainviewcontroller and on it have UIToolbar which has a UIBarButtonItem Info which shows UIViewcontroller modally.
Now when pressing Infobutton it is showing UIViewController modally which has UITextView but not showing UINavigationController with Done button.
I am not able to figure it out what i am missing in my code.
This is how i am showing UITextView and NavigationController in UIViewController modally.
#import "ModalViewController.h"
#import <QuartzCore/QuartzCore.h>
#implementation ModalViewController
#synthesize textView;
#synthesize navBar;
#synthesize navigationController;
#synthesize delegate;
-(void)dealloc
{
[textView release];
[navBar release];
[navigationController release];
[super dealloc];
}
- (void) viewDidLoad
{
[super viewDidLoad];
self.title = #"Info";
UINavigationController *navigationController = [[UINavigationController alloc]init];
//initWithRootViewController:viewController];
self.navigationController.navigationBar.tintColor = [UIColor brownColor];
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(Done:)] autorelease];
self.textView = [[[UITextView alloc] initWithFrame:CGRectMake(0, 0, 320, 416)]autorelease];
self.textView.textColor = [UIColor whiteColor];
self.textView.font = [UIFont fontWithName:#"Georgia-BoldItalic" size:14];
//self.textView.delegate = self;
self.textView.backgroundColor = [UIColor brownColor];
self.textView.layer.borderWidth = 1;
self.textView.layer.borderColor = [[UIColor whiteColor] CGColor];
self.textView.layer.cornerRadius = 1;
self.textView.textAlignment = UITextAlignmentCenter;
self.textView.text = #"This is UITextView presenting modally.\nThis is UITextView presenting modally.\nThis is UITextView presenting modally.\nThis is UITextView presenting modally.\nThis is UITextView presenting modally.\nThis is UITextView presenting modally.
self.textView.editable = NO;
//[self.view addSubview:navigationController.view];
[self.view addSubview: self.textView];
//[navigationController release];
}
And this is how UIViewController presented modally
//Create a final modal view controller
UIButton *modalViewButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[modalViewButton addTarget:self action:#selector(modalViewAction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *modalBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:modalViewButton];
self.navigationItem.rightBarButtonItem = modalBarButtonItem;
- (void) modalViewAction:(id)sender
{
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
//self.viewController = [[ModalViewController alloc] init];
[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
//ModalViewController *myModalViewController = [[ModalViewController alloc] init];
//UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myModalViewController];
//navigationController.navigationBar.tintColor = [UIColor brownColor];
_viewController = [[ModalViewController alloc] init];
//[navigationController pushViewController:_viewController animated:YES];
[self presentModalViewController:self.viewController animated:YES];
//[self.view addSubview:navigationController.view];
//[navigationController release];
[myModalViewController release];
}
I will appreciate if you can figure out what i m doing wrong or missing in my code.
Thanks a lot.
This seems like a needlessly convoluted way of displaying the new controller. In my apps, I do it like this:
//this function displays (modally) view controller nested inside a navcontroller
- (void) showModalController
{
YourViewController * ecreator = [[YourViewController alloc] initWithNibName:#"YourViewController" bundle:nil];
UINavigationController * navcontrol = [[UINavigationController alloc] initWithRootViewController: ecreator];
[self presentModalViewController: navcontrol animated:YES];
[navcontrol release];
[ecreator release];
}
Now you want to do the graphical setup (navbar color etc) in the initWithNib and/or viewDidLoad functions of the YourViewController.
#synthesize navigationController;
so navigationController is your class member variable.
in the function
- (void) viewDidLoad
you declare a local variable
UINavigationController *navigationController
Please notice that the second navigationController is different from your member variable navigationController .
So, inside viewDidLoad you need to create object of your member variable navigationController. Not the local variable navigationController.
Do not RE-declare navigationController in viewDidLoad. Instead, create the object using member variable like:
navigationController = [[UINavigationController alloc]init];
Try this, it worked great for me. I had the exact same problem
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:#“segue_name"])
{
UINavigationController *nav = [segue destinationViewController];
ExampleViewController *exampleVC = (ExampleViewController *) nav.topViewController;
//Setup any properties here and segue
}
}

Set the title of an UIPopOver View Programmatically

How do you set the title of an UIPopOver View programmatically?
I found some sample code but wasn't able to set the title.
myView *theView = [[myView alloc] initWithNibName:#"myView"
bundle:nil];
UIPopoverController* aPopover = [[UIPopoverController alloc] initWithContentViewController:theView];
[aPopover setDelegate:self];
[aPopover setPopoverContentSize:CGSizeMake(320, 320) animated:YES];
[theView setPopover:aPopover];
[theView release];
[self.popoverController presentPopoverFromRect:CGRectMake(510,370,0,0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
You need to wrap the view controller in a UINavigationCotnroller which will add a navigation bar with the appropriate title for the view controller. Something like this:
UINavigationController *container =
[[[UINavigationController alloc] initWithRootViewController:viewController] autorelease];
Then just initialize your popover to use container instead and present it as usual.
yes, exactly. the whole thing could look like this:
InfoView *infoView = [[InfoView alloc] init];
UINavigationController *container = [[[UINavigationController alloc] initWithRootViewController:infoView] autorelease];
UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:container];
infoView.title = #"My Title";
[pop setDelegate:self];
[pop setPopoverContentSize:CGSizeMake(320, 400)];
[pop presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[infoView release];
let popoverContent = (self.storyboard?.instantiateViewControllerWithIdentifier("Popover"))! as UIViewController
popoverContent.title = "Details"
let nav = UINavigationController(rootViewController: popoverContent)
nav.modalPresentationStyle = UIModalPresentationStyle.Popover
let popover = nav.popoverPresentationController
popoverContent.preferredContentSize = CGSizeMake(100, 100)
popover!.delegate = self
popover!.sourceView = self.view
popover!.sourceRect = CGRectMake(100,100,0,0)
self.presentViewController(nav, animated: true, completion: nil)
Try to set the title of the contentViewController of your popOver:
theView.title = #"My Title";
or
theView.navigationItem.title = #"My Title";