How do I change modalTransitionStyle? - objective-c

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];
}

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];
}

Correct way to pushViewController in this case?

I have a custom UITabBarController. On it I have added 3 view controllers adding a navigationController to each one first. It looks like this
ยท customTabBarController.m viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
FirstViewController *firstController = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
UINavigationController *firstNavController = [[UINavigationController alloc] initWithRootViewController:firstController];
SecondViewController *secondController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
UINavigationController *secondNavController = [[UINavigationController alloc] initWithRootViewController:secondController];
self.viewControllers = [NSArray arrayWithObjects:firstNavController, secondNavController, nil];
[self addLeftButtonImage];
[self addRightButtonImage];
self.selectedIndex = 1;
}
Now, when I am on a view controller and I want to pushViewController, how do I have to call it?

Modal View Controller Size

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];
}

iPad Won't Load Modal View

I'm getting this error when loading a modal view.
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x72785a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key aboutTableView.'
It works perfectly fine from the iPhone, but I'm having this trouble with the iPad.
- (IBAction)showOptionsMenu
{
self.optionsNavController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
self.optionsNavController.modalPresentationStyle = UIModalPresentationFormSheet;
self.optionsNavController.modalInPopover = YES;
[self presentModalViewController:self.optionsNavController animated:YES];
}
Update:
This works but the UIButton is not being displayed:
MoreViewController *svc = [[[MoreViewController alloc] init] autorelease];
optionsNavController= [[UINavigationController alloc] initWithRootViewController:svc];
self.optionsNavController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
self.optionsNavController.modalPresentationStyle = UIModalPresentationFormSheet;
self.optionsNavController.modalInPopover = YES;
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]initWithTitle:#"Done" style:UIBarButtonItemStyleBordered target:self action:#selector(dissmissView)];
self.optionsNavController.navigationItem.rightBarButtonItem = doneButton;
[doneButton release];
[self presentModalViewController:self.optionsNavController animated:YES];
Here is a good way to launch a modal view for both devices:
#define IDIOM UI_USER_INTERFACE_IDIOM()
#define IPAD UIUserInterfaceIdiomPad
SomeViewController *svc = [[[SomeViewController alloc] init] autorelease];
if ( IDIOM == IPAD ) {
UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:svc];
[controller setModalPresentationStyle:UIModalPresentationFormSheet];
[controller setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentModalViewController:controller animated:YES];
[controller release];
} else {
/* or you can present the view as modal: */
[self.navigationController pushViewController:svc animated:YES];
}
SomeViewController
-(void)viewDidLoad
{
[super viewDidLoad];
if ( IDIOM == IPAD ) {
UIBarButtonItem *doneButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self action:#selector(dismiss)] autorelease];
self.navigationItem.leftBarButtonItem = doneButton;
}
}
-(void)dismiss
{
[self dismissModalViewControllerAnimated:YES];
}
Are you using different xibs for iphone/ipad?
If so check your connections in your iPad version there is probably a handing connection that you have not removed.

UITableView - Push a View by clicking on a cell

I have created an UITableView with some cells (loaded from an array), when I click on a cell the following code pushes the name with the clicked cell. Is there some easier way to do that? Maybe from within a while loop?
if ([[arrayWeitere objectAtIndex:indexPath.row] isEqual:#"Schulsekretariat"]){
Schulsekretariat *schulsekretariat = [[Schulsekretariat alloc] initWithNibName:#"Schulsekretariat" bundle:nil];
[self.navigationController pushViewController:schulsekretariat animated:YES];
[schulsekretariat release];
}
else if ([[arrayWeitere objectAtIndex:indexPath.row] isEqual:#"Zivilstandesamt"]){
Zivilstandesamt *zivilstandesamt = [[Zivilstandesamt alloc] initWithNibName:#"Zivilstandesamt" bundle:nil];
[self.navigationController pushViewController:zivilstandesamt animated:YES];
[zivilstandesamt release];
}
else if ([[arrayWeitere objectAtIndex:indexPath.row] isEqual:#"Feuerwehr"]){
Feuerwehr *feuerwehr = [[Feuerwehr alloc] initWithNibName:#"Feuerwehr" bundle:nil];
[self.navigationController pushViewController:feuerwehr animated:YES];
[feuerwehr release];
}
NSString *name = [arrayWeitere objectAtIndex:indexPath.row];
Class *myClass = [Class classNamed:name];
myClass *vc = [[myClass alloc] initWithNibName:name bundle:nil];
if (vc != nil) {
[self.navigationController pushViewController:vc animated:YES];
}
[vc release];