Modal View Controller Size - objective-c

I am trying to display a modal view controller, but keep the navigation bar displaying on the iPad. I've tried the different presentation styles but none work. Is it possible to size it, or display it within right on top of a certain view, instead above the whole view controller?
EDIT: Code added:
- (void)buttonPressed:(id)sender
{
RKWebViewController *webViewController = [[RKWebViewController alloc] initWithNibName:nil bundle:nil];
webViewController.request = [NSURLRequest requestWithURL:_link];
webViewController.webView.delegate = self;
webViewController.shouldDisplayDoneButton = YES;
webViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:webViewController animated:YES];
}

Use -
- (void)buttonPressed:(id)sender
{
RKWebViewController *webViewController = [[RKWebViewController alloc] initWithNibName:nil bundle:nil];
webViewController.request = [NSURLRequest requestWithURL:_link];
webViewController.webView.delegate = self;
webViewController.shouldDisplayDoneButton = YES;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:webViewController];
[webViewController release];
navController.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:navController animated:YES];
[navController release];
}

Related

Objective C - Push to a view controller not in tabBarController's tabs programmatically

I have a tab bar controller which contains 3 view controllers, and in 1 of those view controllers, I have a button to present another view controller not in the tab bar controller. The functions in the button run, but the other view controller does not show up. To be more specific, the 3 view controllers in the tab bar is the ProfilePage, EditProfile page and AllUsersProfile page. And in my ProfilePage, I have a logout button to go back to the login screen, which is not part of the tabBar.
Here is my code:
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
// last login
NSString * username = [[NSUserDefaults standardUserDefaults] objectForKey:#"SessionKey"];
Users* lastUser =[LocalStorageController loadCustomObjectWithKey:username];
ProfilePage *lastUserProfile = [[ProfilePage alloc] initWithUser:lastUser];
EditProfile *lastUserEdit = [[EditProfile alloc]initWithUser:lastUser];
AllUsersProfile *lastUserViewAll = [[AllUsersProfile alloc]init];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
NSArray *viewControllers = [NSArray arrayWithObjects:lastUserProfile,lastUserEdit,lastUserViewAll,nil];
[tabBarController setViewControllers:viewControllers animated:NO];
[tabBarController release];
self.window.rootViewController = tabBarController;
lastUserEdit.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Edit Profile" image:nil selectedImage:nil];
lastUserProfile.tabBarItem =[[UITabBarItem alloc] initWithTitle:#"Home" image:nil selectedImage:nil];
lastUserViewAll.tabBarItem =[[UITabBarItem alloc] initWithTitle:#"View Others" image:nil selectedImage:nil];
And here is the code for logout:
- (void) logOut{
[self dismissViewControllerAnimated:YES completion: nil]; //this does not show the LoginScreen view controller
}
Please check the current code to present a new controller in TabBar controllers.
// You have three UIViewControllers
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
ViewControllerTab1 * tabVC1 = [[ViewControllerTab1 alloc] init];
ViewControllerTab2 * tabVC2 = [[ViewControllerTab2 alloc] init];
ViewControllerTab3 * tabVC3 = [[ViewControllerTab3 alloc] init];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
NSArray * viewControllers = [NSArray arrayWithObjects:tabVC1, tabVC2, tabVC3, nil];
[tabBarController setViewControllers:viewControllers animated:NO];
self.window.rootViewController = tabBarController;
tabVC1.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Edit Profile" image:nil selectedImage:nil];
tabVC2.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Home" image:nil selectedImage:nil];
tabVC3.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"View Others" image:nil selectedImage:nil];
}
In ViewControllerTab1, present NewViewController which you want as per your requirement
-(void)presentAnotherVC{
NewViewController * vc = [[NewViewController alloc]init];
[self presentViewController:vc animated:YES completion:nil];
}
In NewViewController, dismiss NewViewController to go back to selected TabBar controller
-(void)dsmissThisVC{
[self dismissViewControllerAnimated:YES completion:nil];
}

UIModalTransitionStyleFlipHorizontal doesn't work

I try to change the modalTransitionStyle property of my modal view. Every style work except for FlipHorizontal. If I choose this, nothing happens.
I have an UINavigationController which should be flipped in.
Heres the code:
UINavigationController *loginNavCon = [[UINavigationController alloc] init];
loginNavCon.navigationBar.barStyle = UIBarStyleBlack;
// push login view
LogInViewController *liVC = [[LogInViewController alloc] initWithStyle:UITableViewStyleGrouped];
[loginNavCon pushViewController:liVC animated:NO];
[liVC release];
// show login view
loginNavCon.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.window.rootViewController presentModalViewController:loginNavCon animated:YES];
[loginNavCon release];
Thanks for your help.
Ok, I figured it out!
The point is to set it in the pushing UIViewController, not in the pushed one.
So in my example code it has to look like this:
UINavigationController *loginNavCon = [[UINavigationController alloc] init];
loginNavCon.navigationBar.barStyle = UIBarStyleBlack;
// push login view
LogInViewController *liVC = [[LogInViewController alloc] initWithStyle:UITableViewStyleGrouped];
[loginNavCon pushViewController:liVC animated:NO];
[liVC release];
// show login view
/** changed **/
self.window.rootViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
/*************/
[self.window.rootViewController presentModalViewController:loginNavCon animated:YES];
[loginNavCon release];

Title of tab bar items not showing

![I am creating a tab bar controller programmatically:
tabBarController = [[UITabBarController alloc] init];
FirstViewController* vc1 = [[FirstViewController alloc] init];
SecondViewController* vc2 = [[SecondViewController alloc] init];
vc1.title = #"Dallas";//[[NSUserDefaults standardUserDefaults] objectForKey:#"Citynamefrmhome"];
vc1.tabBarItem.image = [UIImage imageNamed:#"Dealss.png"];
vc2.title = #"My Vouchers";
vc2.tabBarItem.image = [UIImage imageNamed:#"nav_voucher_S.png"];
NSArray* controllers = [NSArray arrayWithObjects:vc1,vc2, nil];
tabBarController.viewControllers = controllers;
[self.view addSubview:tabBarController.view];
[vc1 release];
[vc2 release];
if I load it when the app starts, it looks great (look at figure 1):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
autoMagically = [[AutoMagically alloc] initWithNibName:nil bundle:nil];
//self.window.rootViewController = self.dummyView;
[self.window addSubview:autoMagically.view];
[self.window makeKeyAndVisible];
return YES;
}
if I load it when a button is clicked, the way i wanna do it, it looks like figure 2. See how the titles arent showing and the buttons seem to be getting cutoff:
- (void)LoadView
{
AutoMagically *autoMagic = [[AutoMagically alloc]
initWithNibName:nil bundle:nil];
self.autoMagically = autoMagic;
[self.view insertSubview:autoMagic.view atIndex:0];
[autoMagic release];
}
Does anyone know why this is behaving like this?]1
You can call
[[[self.parentViewController.tabBarController.tabBar.items objectAtIndex:/*a number based on what tab it was ex: 2*/]setTitle:#"string"];
in your -viewDidLoad or -awakeFromNib methods. It might be better to use the latter instead of the former.

How to use a UIButton to Change Views

How can I changed the view in iPhone development using an UIButton. I do not want to use a toolbar. Thank you
You must have a root view controller
This root view controller switches between the two views.
Something like this:
- (IBAction)switchViews:(id)sender {
if (self.vc1 == nil) {
self.vc1 = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
[self.vc2 removeFromSuperview];
[self.view addSubView:vc1];
vc2 = nil;
}
else {
self.vc2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self.vc1 removeFromSuperView];
[self.view addSubView:vc2];
vc1 = nil;
}
}

How do I change modalTransitionStyle?

I am currently using this code to bring up an info window
-(IBAction)showInfo:(id)sender {
InfoView *info = [[InfoView alloc] initWithNibName:nil bundle:[NSBundle mainBundle]];
[self presentModalViewController:info animated:YES];
[info release];
}
It currently uses the default transition style, UIModalTransitionStyleCoverVertical, and I would like to make it use a different transition style, UIModalTransitionStyleFlipHorizontal for example, how do I do this?
from apple documentation
http://developer.apple.com/iphone/library/samplecode/AddMusic/Listings/Classes_MainViewController_m.html#//apple_ref/doc/uid/DTS40008845-Classes_MainViewController_m-DontLinkElementID_6
MusicTableViewController *controller = [[MusicTableViewController alloc] initWithNibName: #"MusicTableView" bundle: nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController: controller animated: YES];
[controller release];
- (IBAction)next {
page2 *page2_xib = [[page2 alloc] init];
page2_xib.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
//page2_xib.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
//page2_xib.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
//page2_xib.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:page2_xib animated:YES];
}