iPad Won't Load Modal View - objective-c

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.

Related

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

White screen after presenting a modal view controller

I'm getting a white screen after presenting a modal view controller. This is how I do it:
SomeViewController *controller = [[[SomeViewController alloc] initWithManagedObjectContext:managedObjectContext] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
[navController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentModalViewController:navController animated:YES];
The navigation bar works fine, as I set it up in SomeViewController, but the view's contents are not visible, and all I see is the white background color of the root window.
The strange thing is, that this used to work, but now it doesn't for some reason.
What could be the problem?
EDIT:
This is how I create SomeViewController:
- (void)viewDidLoad
{
[super viewDidLoad];
[self setTitle:#"Some View"];
UIBarButtonItem *sortButton = [[[UIBarButtonItem alloc] initWithTitle:#"Sort" style:UIBarButtonItemStylePlain target:self action:#selector(sortButtonClicked:)] autorelease];
[[self navigationItem] setRightBarButtonItems:[NSArray arrayWithObjects:sortButton, [self editButtonItem], nil] animated:YES];
UIBarButtonItem *backButton = [[[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:self action:#selector(dismissModalViewControllerAnimated:)] autorelease];
[[self navigationItem] setLeftBarButtonItem:backButton];
// Hack to force landscape orientation
UIViewController *controller = [[UIViewController alloc] init];
[self presentModalViewController:controller animated:NO];
[self dismissModalViewControllerAnimated:NO];
[controller release];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
The white screen was caused by the xib file of the controller not being part of the target(its target membership checkbox was unchecked).
Do you happen to have some other init meted also in the SomeViewController class? Please post the whole .m file. If so, you can try to delete the initWithNibName method and check if it shows the content.
EDIT:
Another strange point is the initWithManagedObjectContext method you are using on the viewController instance. Can you explain it?
try
SomeViewController *controller = [[[SomeViewController alloc] init] autorelease];
it should work fine.

Dismiss an add contact view controller from a UIPopover

Hi In my app I have a button so when you click it a UIPopover comes up with an add contact view in it. It all workers except when you press save. It doesn't Dismiss.
-(IBAction) addcontact
{
ABNewPersonViewController *contacts = [[ABNewPersonViewController alloc] init];
// imagePicker.delegate = self;
// UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:contacts];
UINavigationController *addContactNavController = [[UINavigationController alloc] initWithRootViewController:contacts];
popover = [[UIPopoverController alloc] initWithContentViewController:addContactNavController];
popover.popoverContentSize = CGSizeMake(320, 1000);
[popover presentPopoverFromRect:CGRectMake(935, 270, 175, 300)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionRight
animated:YES];
[popover retain];
[addContactNavController release];
[contacts release];
}
Implement the ABNewPersonViewControllerDelegate protocol and assign the delegate in your method above –
contacts.newPersonViewDelegate = self;
You can then dismiss the popover in the delegate function –
- (void)newPersonViewController:(ABNewPersonViewController *)newPersonView
didCompleteWithNewPerson:(ABRecordRef)person {
[popOver dismissPopoverAnimated:YES];
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
[popOver release];
}
well,
[self dismissModalViewControllerAnimated:YES];
respecively
[popover dismissPopoverAnimated:YES];
should do it?
Edit: to be more concrete:
....
popover = [[UIPopoverController alloc] initWithContentViewController:addContactNavController];
addContactNavController.delegate = self;
now on saving, do something like:
-(IBAction) saveStuff {
... saving...
[delegate closePopup];
}
and in your File with -(IBAction) addcontact you do:
-(void) closePopup {
[self dismissModalViewCotroller...];
}
makes sense?
and yes, you should add a delegate-propery to your controller if not done yet

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

Exception with TabBar in iPhone SDK

A friend gave me a small tutorial to iPhone programming yesterday.
I then tried to make a small program with two views which I can switch using a TabBar: One with a blue background, one with a red one.
It displays them just fine, but when I run it (in the Simulator) and click on a Tab, it crashed with :
"Terminating app due to uncaught
exception
'NSInvalidArgumentException', reason:
'*** -[NSMachPort
_tabBarItemClicked:]: unrecognized selector sent to instance 0x38223e0"
I didn't manage to find the bug so far... Have you got any ideas ? :)
Code from DemoAppDelegate:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
[window makeKeyAndVisible];
UIColor *color = [UIColor blueColor];
DemoAppViewController *controller1 = [[DemoAppViewController alloc] initWithColor:color];
color = [UIColor redColor];
DemoAppViewController *controller2 = [[DemoAppViewController alloc] initWithColor:color];
[controller1 updateBackground];
[controller2 updateBackground];
UITabBarController *tbcontroller = [[UITabBarController alloc] init];
NSMutableArray *array = [NSMutableArray arrayWithObjects: controller1, controller2, nil];
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:#"Blue" image:nil tag:1];
[controller1 setTabBarItem: item];
[item release];
item = [[UITabBarItem alloc] initWithTitle:#"Red" image:nil tag:2];
[controller2 setTabBarItem: item];
[item release];
[tbcontroller setViewControllers:array];
[tbcontroller setSelectedIndex:0];
[window addSubview: [tbcontroller view]];
[tbcontroller release];
[controller1 release];
[controller2 release];
}
Code excerpt from DemoAppViewController:
- (DemoAppViewController *) initWithColor:(UIColor *)color
{
self = [super init];
if (self != nil) {
[color retain];
backgroundColor = color;
}
return self;
}
- (void) updateBackground
{
UIView *view = [self view];
[view setBackgroundColor: backgroundColor];
}
The problem seems to be in this line: [tbcontroller release];
This is deallocating your tbcontroller. I've commented out that line of code and it works. Try making sure to retain your controller somewhere else since apparently adding the subview isn't doing the job. It may also be related to the viewcontroller themselves being released.