I'm having an issue with the dismissModalViewControllerAnimated method.
The header looks like this:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "GADBannerView.h"
#import "weatherSetUp.h"
#interface weatherPicViewController : UIViewController{
In my viewController.m file I call
-(IBAction)didClickSetting:(id)sender{
weatherSetUp *views = [[weatherSetUp alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:views animated:YES];
}
This all works fine, In my weatherSetUp file once the user has completed set up I was to dismiss the modal view. I do it by calling this method in the above viewController.m file:
-(void)dismissModal{
[self.parentViewController dismissModalViewControllerAnimated:NO];
[self dismissModalViewControllerAnimated:NO];
[self dismissModalViewControllerAnimated:NO];
[self.parentViewController dismissModalViewControllerAnimated:NO];
NSLog(#"Model gone!");
}
But none of these work.
This is the header file of my weatherSetUp file:
#import <UIKit/UIKit.h>
#import "viewController.h"
#interface weatherSetUp : UIViewController
-(IBAction)didClickClose:(id)sender;
#end
And the only method I've implemented is:
-(IBAction)didClickClose:(id)sender{
NSLog(#"CLick ");
viewController *viewEr = [[viewController alloc] init];
[viewEr dismissModal];
}
All the NSLog's work when I click the button, I've searched on here and tried too the above ways of dismissing it and none of them work, any ideas?
What is going wrong is you're calling dismissModal on a random view controller rather than the object that actually has the modal controller. What you'd want to do in didClickClose: is this
[[self parentViewController] dismissModalViewControllerAnimated:NO];
Also, you shouldn't be starting your class names with lowercase characters in Cocoa. They should really be capitalised and have a prefix, eg ABCWeatherSetUp. The prefix can be whatever you want, but generally you want something based on your name, your company's name or your project's name.
insted of [self.parentViewController dismissModalViewControllerAnimated:NO];
write this [self dismissModalViewControllerAnimated:NO];
Your viewEr is not the same viewController which you are trying to close, because you are creating the new object of your viewContoller.
you can create a viewContoller properties and in your viewController class file
weatherSetup.viewController = self.parentViewController;
NOTE: do not use viewContoller as a ivar, use different may name.
Related
im designing a app thats a single view application and i am adding the code so that i can switch views via a button but every-time i enter my code that was working in IOS 5 it now comes up with a error ? heres the code
#import <UIKit/UIKit.h>
#interface ViewController1 : UIViewController
- (IBAction)home:(id)sender;
#end
#import "ViewController1.h"
#import "ViewController.h"
#interface ViewController1 ()
#end
#implementation ViewController1
- (IBAction)home:(id)sender
{
ViewController *second =[[ViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
}
heres the error
thank you!!
edited answers my errors now ??
by the way i really appreciate it and i will give you good tick by your answer once done this is the errors now??
First of all, this is not an error but it is warning.
And for help you can read the documents provided by Apple.
And to remove that warning just use the below code
[self presentViewController:second animated:YES completion:^{ }];
I've been trying to switch two views from two separate view controllers for a while and it never works, the simulator always crashes to the home screen. I'm using Xcode 3.2.5 and this is my code -
SwitchViewsViewController.h
#import <UIKit/UIKit.h>
#import "SecondViewController.h"
#interface SwitchViewsViewController : UIViewController {
}
-(IBAction)pushButton;
#end
SwitchViewsViewController.m
#import "SwitchViewsViewController.h"
#import "SecondViewController.h"
#implementation SwitchViewsViewController
-(IBAction)pushButton {
SecondViewController *screen = [[SecondViewController alloc] initWithNibName:nil bundle:nil
screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:screen animated:YES]
[screen release];
}
SecondViewController.h
#import <UIKit/UIKit.h>
#interface SecondViewController : UIViewController {
}
-(IBAction)pushBack;
#end
SecondViewController.m
#import "SecondViewController.h"
#implementation SecondViewController
-(IBAction)pushBack{
[self dismissModalViewControllerAnimated:YES];
}
In interface builder, all i've done is linked the file's owner classes and the buttons. Also made the SwitchViewsViewController load first, and not MainWindow. Everything builds but when I try to run the app it crashes and sends it to the home screen. Can anyone help me with this?
When you alloc your secondViewController you init with nib name nil, this should actually be the name of your nib file.
SecondViewController *screen = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
Also, you should close your brackets ;-)
XIB errors are rarely uncovered at compile time. So when you say you made SwitchViewsViewController the starting point of the app, I am assuming that you have altered the main nib file in Info.plist. Usually that nib file is responsible for providing information about the application delegate. So it's a pretty bad idea if you've changed it to SwitchViewsViewController. I suggest you incorporate the MainWindow.xib back. This is easier I think but if you are interested in doing programmatically than take a look at this post.
I have a UIViewController which shows different UIViewController sub-classes. In the main UIViewController.m, I have a sub-class called 'Home' load on app start.
Now, which the Home view loaded, I have a button which I want to use to switch to another view called 'PreGameInfo'. I'm trying to use the code below:
- (IBAction)showPreGameInfo:(id)sender {
[self.view insertSubview:preGameInfo.view atIndex:0];
}
It doesn't work, and I know it's because the 'self.view' needs to refer to the main UIViewController rather than the self of the 'Home' view. Does anyone know how to insertSubView to the main UIViewController when using a UIButton whilst in a SubView???
Thank you!
You can use a delagate. It very easy
So implement this in your information view controller;
In the InformationViewController.h
#protocol InformationViewControllerDelegate;
#interface InformationViewController : UIViewController {
id <InformationViewControllerDelegate> delegate;
}
#property (nonatomic, assign) id <InformationViewControllerDelegate> delegate;
- (IBAction)returnBack:(id)sender;
#end
#protocol InformationViewControllerDelegate
- (void)InformationViewControllerDidFinish:(InformationViewController *)controller;
#end
in the InformationViewController.m
- (IBAction)returnBack:(id)sender {
[self.delegate InformationViewControllerDidFinish:self];
}
And use the delegate in any view controller you need it like this :
In the HomeViewController.h
#import "InformationViewController.h"
#interface HomeViewController : UIViewController <InformationViewControllerDelegate> {
}
Write the method to change the view from Home view to Information view
- (IBAction)goToInformationView:(id)sender;
In the HomeViewController.m
- (IBAction)goToInformationView:(id)sender {
InformationViewController *controller = [[InformationViewController alloc] initWithNibName:nil bundle:nil];
controller.delegate = self;
// You can chose the transition you want here (they are 4 see UIModalTransitionStyle)
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
And the last but not least the delegate method it inform the HomeViewController when the InformationViewController had finished
- (void)InformationViewControllerDidFinish:(InformationViewController *)controller {
[self dismissModalViewControllerAnimated:YES];
}
I hope it helps
- (IBAction)showPreGameInfo:(id)sender {
[superview insertSubview:preGameInfo.view atIndex:0];
}
Does this code work?
[self.parentViewController.view addSubview:myView];
Just do it in the modalView:
[self presentModalViewController:preGameInfo animated:YES]
or you can do something like this...
This line will add your new view to windows rootViewControllers view
[self.view.window.rootViewController.view addSubview:preGameInfo.view];
I'm trying to set it up so people can email from within my application. I'm referencing this post to do this, but I'm getting these warnings on the build:
and then when I run it, it bugs:
I'm wondering if I've simply placed the code in the wrong area. Just so you know I have placed
#import <MessageUI/MessageUI.h>
in the header file.
Thanks for the help!
EDIT 1
It seems as if the problem lies within how my ViewController is setup. In fact all my UI code is in a separate object as shown below. This is making it difficult for me to understand which code goes where. Any advice?
Add the MessageUI framework into your framework folder and
import these classes in your viewController.h:-
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#interface *your controller* : UIViewController <MFMailComposeViewControllerDelegate>
Well it looks like your SpeakHereController isn't a UIViewController.
Therefore it can't find the methods for presenting and dismissing the modalViewController.
Also you need to implement the MFMailComposeViewControllerDelegate, add it to your viewcontroller.
Here is the code
#import <UIKit/UIKit.h>
#import <MessageUI/MFMailComposeViewController.h>
#interface tempsend : UIViewController<MFMailComposeViewControllerDelegate>
//.m file code
MFMailComposeViewController *picmail = [[MFMailComposeViewController alloc] init];
picmail.mailComposeDelegate = self;
[picmail setSubject:#"Exporting DDT file"];
// Set up recipients
[picmail setToRecipients:[NSArray arrayWithArray:aray_emailid]];
[picmail setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picmail animated:YES];
[picmail release];
Regards,
Shyam
Add MFMailComposeViewControllerDelegae to SpeakHereController.h file
And use
[controlle presentModalViewController:controller animated:YES];
Instead of
[self presentModalViewController:controller animated:YES];
Same for
[controlle dismissModalViewControllerAnimated:YES];
Instead of
[self dismissModalViewControllerAnimated:YES];
I create a UIViewController with a button on it. The button's only job is to create a window for drawing some rectangles. (I've taken some code from "QuartzDemo" from Apple's example applications.) Objective C is really giving me fits...
When I try this, nothing happens.
Here's the code for the button:
- (IBAction)startButtonAct:(id)sender
{
QuartzViewController *controller;
NSLog(#"1");
controller = [[QuartzViewController alloc] initWithTitle:#"Dotsie"];
controller.quartzViewDelegate = [[[RectDrawing alloc] init] autorelease];
[[self navigationController] pushViewController:controller animated:YES];
// [controller release];
}
I'm honestly not sure what else anyone needs to see, but here's some of the other stuff:
#interface QuartzViewController : UIViewController
{
QuartzView *quartzView;
UIBarStyle barStyle;
UIStatusBarStyle statusStyle;
}
#protocol QuartzViewDelegate;
#interface QuartzView : UIView {
id<QuartzViewDelegate> delegate;
}
#property(assign) id<QuartzViewDelegate> delegate;
#end
#protocol QuartzViewDelegate<NSObject>
#required
// Draw contents into the given view, using the given context and bounds.
-(void)drawView:(QuartzView*)view inContext:(CGContextRef)context bounds:(CGRect)bounds;
#end
Please help -- this is driving me crazy -- I've been fighting with the same basic problem now for a week...
First, the [controller release] line should be there, uncommented. I'm sure you just disabled it for debugging.
If you insert the line:
NSLog(#"%#", [self navigationController]);
In your button action, does it log a valid controller or does it say nil? If it's nil, my guess is that this view controller wasn't properly pushed onto a navigation controller itself.