Okay after finding a couple of tutorials online. Everything is okay except when the button is being pressed. I pressed the button that will sent an email and suddenly there is a signal abort. I watched two videos and re type every code in each video twice. Why is there a signal abort? Please help. Thank you!
this is the .h file
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <MessageUI/MFMailComposeViewController.h>
#interface secondViewController : UIViewController <MFMailComposeViewControllerDelegate> {
IBOutlet UILabel *resultLabel;
}
-(IBAction)switchToFirst:(id)sender;
-(IBAction)openMail:(id)sender;
#end
this is the .m file
#import "secondViewController.h"
#import "ViewController.h"
#interface secondViewController ()
#end
#implementation secondViewController
-(IBAction)openMail:(id)sender {
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
[composer setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail]) {
[composer setToRecipients:[NSArray arrayWithObjects:#"", nil]];
[composer setSubject:#""];
[composer setMessageBody:#"message" isHTML:YES];
[composer setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[self presentModalViewController:composer animated:YES];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"ERROR" message:#"Can't send your email!" delegate:self cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil];
[alert show];
}
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
switch (result) {
case MFMailComposeResultSent:
resultLabel.text = #"Mail was sent";
break;
case MFMailComposeResultSaved:
resultLabel.text = #"Mail was saved to drafts";
break;
case MFMailComposeResultFailed:
resultLabel.text = #"Mail wasn't able to sent";
break;
case MFMailComposeResultCancelled:
resultLabel.text = #"Mail was Cancelled";
break;
}
[self dismissModalViewControllerAnimated:YES];
}
-(IBAction)switchToFirst:(id)sender {
ViewController *second = [[ViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// Set the background image by setting the contents of the view's layer
UIImage *bg = [UIImage imageNamed:#"iPad iDeaf Assisstant Background.png"];
self.view.layer.contents = (id) [bg CGImage];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
If you have a class for email sending you can compile it without arc, just set flag -fno-objc-arc for files in project settings->build phases
Like #qegal said, just take out all the retains and releases.
And if you want to keep the code you have, you can just mark files as non-arc.
To mark any file as non-arc you can set a compiler flag in the build phases. Select your project in the files pane on the left hand side. Then select your target, go to build phases, and double click the column underneath compiler flags for the file you want to mark and enter 'fno-objc-arc'.
Related
Im newish to Objective-C and I want to create an app with that will eventually take pictures with the camera but with images overlaid. But I thought I would start with a simple camera app just to get the base for it. I have followed a tutorial for creating a app that you can take pictures with and access image library. BUT when I build it to my iPhone 4s it just loads a white screen. If any one could take a look at the code, but I think its right and offer an answer it would be great thanks.
//ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
#property (strong, nonatomic) IBOutlet UIImageView *imageView;
- (IBAction)takePhoto:(UIButton *)sender;
- (IBAction)selectPhoto:(UIButton *)sender;
#end
//ViewController.m
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Device has no camera"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[myAlertView show];
}
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
- (IBAction)takePhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)selectPhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
#pragma mark - Image Picker Controller delegate methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
#end
How to change my profile picture image, when I click on done button in second screen the first screen image should change with the second screen image.
I am selecting image from Gallery that image was appearing in my second screen how to set this image in first screen view controller while I am clicking on done button.
This is MprofileViewController.h
#import <UIKit/UIKit.h>
#import "AddProfileViewController.h"
#class MProfileViewController;
#interface MProfileViewController : UIViewController<UIImagePickerControllerDelegate,UITableViewDataSource,UITableViewDelegate,ImageSelectionDelegate>
{
NSMutableArray* titles;
IBOutlet UITableView *mainTableView;
IBOutlet UIImageView *image2;
}
#property(strong,nonatomic)IBOutlet UIImageView *image2;
#property(nonatomic, retain) NSMutableArray *titles;
#property(strong,nonatomic)UITableView *mainTableView;
-(IBAction) clickEventOnImage:(id) sender;
#end
MprofileViewController.m
#import "MProfileViewController.h"
#interface MProfileViewController ()
#end
#implementation MProfileViewController
#synthesize titles,mainTableView;
#synthesize image2;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
titles=[[NSMutableArray alloc]init];
self.navigationItem.title = #"View Profile";
image2.image=[UIImage imageNamed:#"hariku-indah.jpg"];
}
- (void) imageSelected:(UIImage *)image {
// Use image
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction) clickEventOnImage:(id) sender{
AddProfileViewController *Avc = [[AddProfileViewController alloc]initWithNibName:#"AddProfileViewController" bundle:nil];
Avc.delegate=self;
[self.navigationController pushViewController:Avc animated:YES];
}
- (void)viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO];
}
#end
AddProfileViewController.h
#import <UIKit/UIKit.h>
#protocol ImageSelectionDelegate <NSObject>
- (void) imageSelected:(UIImage*)image;
#end
#interface AddProfileViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIActionSheetDelegate>{
IBOutlet UIImageView *imageView;
NSData *dataImage;
}
// Delegate property
#property (nonatomic,assign) id<ImageSelectionDelegate> delegate;
#property (strong, nonatomic) IBOutlet UIImageView *imageView;
-(IBAction)back:(id)sender;
-(IBAction)done:(id)sender;
#end
AddprileViewController.m
#import "AddProfileViewController.h"
#import "MProfileViewController.h"
#interface AddProfileViewController ()
#property(strong,nonatomic) UIImagePickerController *imagePicker;
#end
#implementation AddProfileViewController
#synthesize imageView;
#pragma mark -
#pragma mark View lifecycle
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(#"actionSheet");
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 0) {
[self pushTakePhotoScreenInDelegate];
}
else if (buttonIndex == 1) {
[self pushChoosePhotoScreenInDelegate];
}
}
-(void)pushTakePhotoScreenInDelegate
{
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"viewfinder_2.png"]];
CGSize screenSize = [UIScreen mainScreen].bounds.size;
[imageView setFrame:CGRectMake(0, -52/2.0, screenSize.width, screenSize.height)];
self.imagePicker.cameraOverlayView = imageView;
self.imagePicker.delegate = self;
[self presentViewController:self.imagePicker animated:YES completion:nil];
}
-(void)pushChoosePhotoScreenInDelegate
{
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.imagePicker.delegate = self;
[self presentViewController:self.imagePicker animated:YES completion:nil];
}
//-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
self.imageView.image = image;
[picker dismissViewControllerAnimated:YES completion:nil];
}
// In case you are using image picker, this delegate is called once image selection is complete.
//- (void)imagePickerController:(UIImagePickerController *)picker
//didFinishPickingMediaWithInfo:(NSDictionary *)info
//{
//Use either according to your setting, whether you allow image editing or not.
//self.imageView.image = image;
//UIImage *myImage = [info objectForKey:UIImagePickerControllerEditedImage];
//For edited image
// UIImage *myImage = [info objectForKey:UIImagePickerControllerOriginalImage];
//if([_delegate respondsToSelector:#selector(imageSelected:)]) {
// [self.delegate imageSelected:myImage];
// }
//}
/*
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:nil];
UIImage * pickedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
AddProfileViewController * controller = [AddProfileViewController new];
controller.imageView.image = pickedImage;
// [self.navigationController pushViewController:controller animated:YES];
}*/
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self.navigationController dismissModalViewControllerAnimated:YES];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Select Image from..."
delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Take Photo", #"Choose from library", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view];
}
-(IBAction)back:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
-(IBAction)done:(id)sender
{
// if([_delegate respondsToSelector:#selector(imageSelected:)]) {
// [self.delegate imageSelected:imageView];
// }
[self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)viewWillAppear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:YES];
}
#end
// if([_delegate respondsToSelector:#selector(imageSelected:)]) {
// [self.delegate imageSelected:imageView]; }
This code is technically correct. But you forgot to synthesize your delegate in AddprofileViewController
How can I assure that UIImagePickerController always returns a squared image?
WhatsApp does it but I have not found a way to achieve this.
How it is in my App (Build in iOS 7)
How it should be (WhatsApp - iOS 6)
My code:
- (IBAction)showImagePicker:(id)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
if ([sender tag] == 1) {
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else {
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
[self presentModalViewController:imagePicker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
_imageView.image = [info objectForKey:UIImagePickerControllerEditedImage];
[self dismissModalViewControllerAnimated:YES];
}
well to change the size of the image captured you need to set the mode for view in your UIImageView in IB to scale to fill. then when the image is chosen from library or from camera, it automaticaly will be resized. you do have to turn the autolayout off though since it wont allow the ImageView to be resized. you code is fine. anyhow here is sample app codes you can build to understand it a bit better.
.h
#import <UIKit/UIKit.h>
#interface ImageTestViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
#property (strong, nonatomic) IBOutlet UIImageView *imageView;
- (IBAction)takePhoto: (UIButton *)sender;
- (IBAction)selectPhoto:(UIButton *)sender;
#end
.m
#import "ImageTestController.h"
#interface ImageTestViewController ()
#end
#implementation ImageTestViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Device has no camera"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[myAlertView show];
}
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
- (IBAction)takePhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)selectPhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
#end
in the ImageTestController Xib or view in storyboard, place two buttons, one for each action and create the necessary links in IB. then place a UIImageView to fill whatever size you want in the view. click the UIImageView and in view section of attribute inspector change the mode to scale to fill. turn the autolayout off. try adding an image to your simulator just to test it. make sure the image is of the landscape size. build and run and when you select the image from image library, it will automatically resize to square or any other size you set your UIImageView.
i know you are aware of most of the steps above, but i wrote this answer not to just help you get rid of your issue but for others that may have similar issues. hope it helps you out man.
I am trying out a simple camera app for practice. Was following these examples: iOS 6 App
and iOS 4 App
My code looks like this:
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController<UINavigationControllerDelegate, UIImagePickerControllerDelegate>
{
UIButton *button;
UIImageView *imageView;
}
#property (nonatomic, retain) IBOutlet UIImageView *imageView;
- (IBAction)useCamera;
- (IBAction)useCameraRoll;
#end
ViewController.m
#import "ViewController.h"
#import <MobileCoreServices/MobileCoreServices.h>
#interface ViewController ()
#end
#implementation ViewController
#synthesize imageView;
- (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex
{
// After saving iamge, dismiss camera
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;
// Unable to save the image
if (error)
alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Unable to save image to Photo Album."
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
else // All is well
alert = [[UIAlertView alloc] initWithTitle:#"Success"
message:#"Image saved to Photo Album."
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
// Save image
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);
}
- (id)init
{
if (self = [super init])
{
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.view.backgroundColor = [UIColor grayColor];
// Button to activate camera
button = [[UIButton alloc] initWithFrame:CGRectMake(80, 55, 162, 53)];
[button setBackgroundImage:[UIImage imageNamed:#"Camera.png"] forState:UIControlStateNormal];
[button addTarget:self action:#selector(buttonPressed:) forControlEvents: UIControlEventTouchUpInside];
[self.view addSubview:button];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)useCamera
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
- (IBAction)useCameraRoll
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
#end
My problem I like to access the camera from the app itself. What happens is that when i click useCamera button, it opens up the camera and take the image. Is it possible it could do that from the app itself? Sorry if it is a stupid question. Do point me out if I am doing something wrong.
Yes, use the UIImagePickerController class.
When the camera button is clicked, present an instance of UIImagePickerController. Also, since some iOS devices like the original iPad or some older iPod touches don't have cameras, I wouldn't recommend using separate buttons/methods for taking a new picture vs using one from the saved photos. Use one button and set its source type based on the device's capabilities using the available methods in the class. It may require rethinking your app's design, but it's also more likely to pass Apple's UI inspection, as they may not approve an app that has a button exclusively for taking a picture but can run on a device without a camera.
Once the user has either taken a new photo or chosen a photo from either the camera roll, use the imagePickerController:didFinishPickingMediaWithInfo: method from the UIImagePickerControllerDelegate class to pass the user's choice to your code.
Instances of UIImagePickerController are designed to be presented modally on all iOS devices when using the camera. Remember, as the name suggests, they are controllers and NOT views, so they shouldn't be used as subviews of UIView. While it may be possible to get creative with how you present it, you'll almost certainly have some side-effects and you'll further increase the chance that Apple will reject it. It only SEEMS like it's getting out the app to take the photo, but because you're presenting the controller from your app, it's still very much a part of it. Apple doesn't allow direct access to the camera hardware, which is exactly why they've created this class.
I am stuck in a tutorial, trying to switch views with a toolbar. My code builds fine and I put some alerts in to check the toolbar was working, and it is. But my subviews I am inserting are just not showing up at all. Can anybody help please?
Here is my main controller code..
MainViewController.h is
#import
#class FlavourPickerView;
#class ShakeView;
#class ResultsView;
#interface MainViewController : UIViewController {
IBOutlet FlavourPickerView *flavourPickerView;
IBOutlet ShakeView *shakeView;
IBOutlet ResultsView *resultsView;
}
#property (retain,nonatomic) FlavourPickerView *flavourPickerView;
#property (retain,nonatomic) ShakeView *shakeView;
#property (retain,nonatomic) ResultsView *resultsView;
-(IBAction)loadFlavourPickerView:(id)sender;
-(IBAction)loadShakeView:(id)sender;
-(IBAction)loadResultsView:(id)sender;
-(void)clearView;
#end
and here is MainViewController.m
#import "MainViewController.h"
#import "FlavourPickerView.h"
#import "ShakeView.h"
#import "ResultsView.h"
#implementation MainViewController
#synthesize flavourPickerView;
#synthesize shakeView;
#synthesize resultsView;
-(IBAction)loadFlavourPickerView:(id)sender{
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc]
initWithTitle:#"Flavour selected"
message:#"Seems to work"
delegate:nil
cancelButtonTitle:#"OK!"
otherButtonTitles:nil];
[alertDialog show];
[alertDialog release];
[self clearView];
[self.view insertSubview:flavourPickerView.view atIndex:10];
}
-(IBAction)loadShakeView:(id)sender{
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc]
initWithTitle:#"Shaker selected"
message:#"Seems to work"
delegate:nil
cancelButtonTitle:#"OK!"
otherButtonTitles:nil];
[alertDialog show];
[alertDialog release];
[self clearView];
[self.view insertSubview:shakeView.view atIndex:0];
}
-(IBAction)loadResultsView:(id)sender{
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc]
initWithTitle:#"Results selected"
message:#"Seems to work"
delegate:nil
cancelButtonTitle:#"OK!"
otherButtonTitles:nil];
[alertDialog show];
[alertDialog release];
[self clearView];
[self.view insertSubview:resultsView.view atIndex:0];
}
-(void)clearView{
if(flavourPickerView.view.superview){
[flavourPickerView.view removeFromSuperview];
}else if(shakeView.view.superview){
[shakeView.view removeFromSuperview];
}else{
[resultsView.view removeFromSuperview];
}
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[self loadFlavourPickerView:nil];
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[flavourPickerView release];
[shakeView release];
[resultsView release];
[super dealloc];
}
#end
and here is an example of one of the other views, starting with FlavourPickerView.h
#import
#interface FlavourPickerView : UIViewController {
}
#end
and FlavourPickerView.m
#import "FlavourPickerView.h"
#implementation FlavourPickerView
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
There is also a nib for the flavourPickerView and I have added subviews into my mainView, with the Class set to FlavourPickerView and nib name is FlavourPickerView.xib.
Are flavourPickerView, shakeView, and resultsView properly initialized when you add their view to this UIViewController view?
Another thing: avoid to call a UIViewController just 'XXXView', try instead 'XXXViewController'