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:^{ }];
Related
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.
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'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 am trying to implement a modal navigation controller as described in the Apple iOs Guide: Combined View Controller Interfaces
I have come to the conclusion that I am missing something both obvious and stupid as I simply cannot get anything to display, I get a blank white screen.
Swapping things out I can prove that the view controller that I am using as the navigation controllers RootViewController works fine on it's own (by adding it manually as a view subChild).
Further, implementing addSubView ([self.view addSubview:navController.view]) instead of presentModalViewController seems to work OK.
Can anyone point out my simple error because I am 5 minutes short of kicking my own face :D
header
#import <UIKit/UIKit.h>
#interface BaseViewController : UIViewController {
}
implementation
#import "BaseViewController.h"
#import "ScannedListViewController.h"
#import "ScannedItemViewController.h"
#implementation BaseViewController
- (void)viewDidLoad {
ScannedListViewController *listViewController = [[ScannedListViewController alloc] init];
ScannedItemViewController *itemViewController = [[ScannedItemViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:listViewController];
[navController pushViewController:itemViewController animated:NO];
[self presentModalViewController:navController animated:YES];
[listViewController release];
[itemViewController release];
[navController release];
[super viewDidLoad];
}
The RootControllerView is a basic test TableViewController with the following header
#interface ScannedListViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>
Thank you in advance if your able to help
Why are you presenting something modally in a view controller's viewDidLoad method? I find that odd off the top. Generally you show a modal view controller in response to some action (like tapping a button).
Is there a reason you're showing a navigation controller with a second view controller already pushed on it after the root?
You should have [super viewDidLoad] as the first line, not the last line, of the method.
You do not need to have <UITableViewDelegate, UITableViewDataSource> after UITableViewController because it already adopts those protocols. Remove that bit.
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.