iPhone iOS 6 - Dismissing a subview crashes - iphone

I can't quite figure out what's going on but I have a view that displays a subview when a users selects a button. This subview then also has a button the user can select to cancel and remove this subview. When all of this happens, my app crashes when you attempt to close the subview.
This is my code:
From the main view that shows the subview when a button is selected -
-(IBAction)sendMessage:(id)sender{
NSLog(#"Going to send a message....");
CGRect frameBounds = [self.view bounds];
float frameWidth = frameBounds.size.width;
float frameHeight = frameBounds.size.height;
float frameX = frameBounds.origin.x;
//float frameY = frameBounds.size.height / 2;
float frameY = frameBounds.size.height;
float finalY = frameBounds.size.height / 1.75;
MessageChooserController *chooser = [[MessageChooserController alloc] initWithNibName:#"MessageChooser" bundle:nil];
//Set the frame off the screen at the bottom
chooser.view.frame = CGRectMake(frameX, frameY, frameWidth, frameHeight);
[self.view addSubview:chooser.view];
[UIView animateWithDuration:0.5 animations:^{chooser.view.frame = CGRectMake(frameX, finalY, frameWidth, frameHeight);}];
}
As you can see this simply shows a new subview - MessageChooserController. Now this subview, MessageChooserController has a button to cancel this "action".
The header file for MessageChooserController:
#import <UIKit/UIKit.h>
#interface MessageChooserController : UIViewController
#property (weak, nonatomic) IBOutlet UIButton *btn_sendEmail;
#property (weak, nonatomic) IBOutlet UIButton *btn_sendText;
#property (weak, nonatomic) IBOutlet UIButton *btn_cancel;
-(IBAction)closeChooser:(id)sender;
#end
And its implementation:
#import "MessageChooserController.h"
#interface MessageChooserController ()
#end
#implementation MessageChooserController
#synthesize btn_cancel, btn_sendEmail, btn_sendText;
- (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.
/*
[btn_cancel setBackgroundImage:[[UIImage imageNamed:#"iphone_delete_button.png"] stretchableImageWithLeftCapWidth:8.0f topCapHeight:0.0f] forState:UIControlStateNormal];
*/
/*
UIImage *cancelButtonImage = [[UIImage imageNamed:#"iphone_delete_button"] resizableImageWithCapInsets:UIEdgeInsetsMake(30,0,30,0)resizingMode:UIImageResizingModeStretch];
[btn_cancel setBackgroundImage:cancelButtonImage forState:UIControlStateNormal];
*/
}
-(IBAction)closeChooser:(id)sender{
[self.view removeFromSuperview];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
As you can see I have a simple method to close this subview, closeChooser. All of this compiles but when I select the cancel button on the subview my app crashes. I can't find anything anywhere about this.
Essentially I want to have a view display like it does when you select "Send message" from your contacts.

The correct way of doing this is calling [self presentModalViewController:viewController] on the parent view controller and then calling [self dismissModalViewController] when you want to hide it.

Related

UIScrollView won't scroll when re-entering view

I have a UIView (inside a View Controller, of course), and inside this UIView, I have a UIScrollView. UIScrollView contains some images and buttons. One of the buttons uses the modal Action Segue and opens up a UIView with a MapView inside, and a "back" button at the bottom that takes you back to the previous UIView. But upon going "back" (from the MapView to the UIView), the UIScrollView does not scroll anymore like it did before going to the MapView and back. It's like it's locked in its top position. I feel like it has something to do with delegates? I dunno though, I'm not too clear on those yet. Anyway, any insight to my scrolling issue?? Thanks!!
Here's my .h file (where my scroll view is):
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#interface ThirdViewController : UIViewController <UIScrollViewDelegate, UIScrollViewAccessibilityDelegate>
#property (strong, nonatomic) IBOutlet UIView *findUsView;
#property (weak, nonatomic) IBOutlet UIScrollView *findUsScrollView;
- (IBAction)callButton:(id)sender;
- (IBAction)getDirButton:(id)sender;
#end
Here's my .m file (where my scroll view is):
#import "ThirdViewController.h"
#implementation ThirdViewController
- (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.
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"appBackgroundColor.png"]];
[self.view addSubview:self.findUsScrollView];
}
-(void)viewWillAppear:(BOOL)animated{
//this line creates the frame of the scrollview (dimensions)
[self.findUsScrollView setFrame:CGRectMake(0, 0, 0, 750)];
[super viewWillAppear:animated];
}
-(void)viewDidAppear:(BOOL)animated
{
//dimensions of content within scrollveiw. Scrolling enabaled.
[self.findUsScrollView setScrollEnabled:YES];
[self.findUsScrollView setContentSize:CGSizeMake(0, 751)];
[super viewWillAppear:animated];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)callButton:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:0000000000"]];
}
- (IBAction)getDirButton:(id)sender {
}
#end
Here's the .h file for the Map View:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface MyMapViewController : UIViewController <MKMapViewDelegate, MKAnnotation>
#property (weak, nonatomic) IBOutlet MKMapView *mapView;
#property (weak, nonatomic) IBOutlet UINavigationBar *titleBarMap;
#property (weak, nonatomic) IBOutlet UIToolbar *bottomNavBarMap;
#property (weak, nonatomic) IBOutlet UIView *topTitlesOverlay;
- (IBAction)backButtonMap:(id)sender;
#end
Here's the .m file for the Map View:
#import "MyMapViewController.h"
#implementation BountMapViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (IBAction)backButtonMap:(id)sender {
[self dismissViewControllerAnimated:YES completion: ^(void){
ThirdViewController *vc = (ThirdViewController *)[self presentingViewController];
[[vc findUsScrollView] becomeFirstResponder];
}];
}
#end
Try moving [self.findUsScrollView setFrame:CGRectMake(0, 172, 320, 680)]; and [self.findUsScrollView setContentSize:CGSizeMake(320, 680)]; to viewDidLoad as a first suggestion. You don't want those to be called everytime your view appears.
Second, your contentSize and frameSize are the same (320, 680). This means your UIScrollView does not need to scroll. Remember: for a UIScrollView to scroll it's content size must be bigger than it's frame size. That should be all, and of course: setScrollEnabled: YES;
Your override of viewDidAppear is calling [super viewWillAppear:] instead of [super viewDidAppear:]

[PointInfoController endAppearanceTransition]: message sent to deallocated instance 0x74d5e90

I need a little help here, I've loaded a view by modal and basically I'm now trying to dismiss this view now but it keep crashing after the view goes.
It says * -[PointInfoController endAppearanceTransition]: message sent to deallocated instance 0x74d5e90
Below is the .H file:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#class PointInfoController;
#protocol PointInfoDelegate
- (void)PointInfoDidFinish:(PointInfoController*)PointInfoController;
#end
#interface PointInfoController : UIViewController <UIScrollViewDelegate>
{
IBOutlet UIScrollView *scrollView;
IBOutlet UIImageView *thumbnailView;
IBOutlet UIButton *Dismiss;
id<PointInfoDelegate> delegate;
}
#property (retain) id<PointInfoDelegate> delegate;
#property (retain, nonatomic) IBOutlet UITextView *description;
#property (retain, nonatomic) IBOutlet UIScrollView *scrollView;
#property (retain, nonatomic) IBOutlet UIImageView *thumbnailView;
- (IBAction)DismissView:(id)sender;
#end
Below is the .M file:
#import "PointInfoController.h"
#import "LockOnLocation.h"
#implementation UIScrollView (AutoContentSize)
- (void) setAutosizeContent:(BOOL)autosizeContent {
if (autosizeContent) {
CGFloat contentWidth =
self.frame.size.width == self.superview.frame.size.width ?
self.superview.frame.size.width :
self.frame.size.width + 10;
CGFloat contentHeight =
self.frame.size.height == self.superview.frame.size.height ?
self.superview.frame.size.height :
self.frame.size.height + 164;
self.contentSize = CGSizeMake(contentWidth, contentHeight);
}
}
#end
#implementation PointInfoController
#synthesize description;
#synthesize scrollView;
#synthesize thumbnailView;
#synthesize delegate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (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.
}
#pragma mark - View lifecycle
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
self.scrollView.delegate = self;
[super viewDidLoad];
}
- (void)viewDidUnload
{
[self setDescription:nil];
[scrollView release];
scrollView = nil;
[self setScrollView:nil];
[self setThumbnailView:nil];
[thumbnailView release];
thumbnailView = nil;
[Dismiss release];
Dismiss = nil;
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (IBAction)DismissView:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
[self release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)dealloc {
[description release];
[scrollView release];
[thumbnailView release];
[Dismiss release];
[super dealloc];
}
#end
I'm new to all this and I spent quite a few days on the same problem. Blamed everything but myself! I discovered I was inadvertently release(ing) the instance referred to. In my case I had put the instance into a SSLConnectionRef and CFRelease'd it. I'm not sure why you are having the issue looking at your code. In any event, I thought your compiler would complain about your [instance release] methods, since these are no longer allowed. You are having the problem because both you and the system are releasing the instance. You need to get rid of your release and all will be well.

tableHeaderView doesn't display UIView properly

I'm trying to add UIScrollView with paging as a header to my table, but unfortunately it is not displayed correctly.
The htableHaderView is resized to the size of my imagesScrollView, but only half of it is displayed the rest area is blank.
- (void)viewDidLoad
{
[super viewDidLoad];
ImagesViewController *imagesScrollView = [[ImagesViewController alloc] initWithNibName:#"ImagesViewController" bundle:nil];
tableView.tableHeaderView = imagesScrollView.view;
imagesScrollView = nil;
}
Thanks for helping
I tried the following code:
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UITableViewController
#end
ViewController.m
#import "ViewController.h"
#import "ImagesViewController.h"
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
ImagesViewController *imageVC = [[ImagesViewController alloc] initWithNibName:#"ImagesViewController" bundle:nil];
[[self tableView] setTableHeaderView:[imageVC view]];
imageVC = nil;
}
#end
ImagesViewController.h
#import <UIKit/UIKit.h>
#interface ImagesViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIScrollView *ScrollView;
#property (strong, nonatomic) IBOutlet UIView *ViewInScrollView;
#end
ImagesViewController.m
#import "ImagesViewController.h"
#implementation ImagesViewController
#synthesize ScrollView;
#synthesize ViewInScrollView;
- (void)viewDidLoad {
[super viewDidLoad];
[[self ViewInScrollView] setFrame:CGRectMake(0, 0, 768 * 2, 400)];
[[self ViewInScrollView] setBackgroundColor:[UIColor orangeColor]];
[[self ScrollView] setContentSize:[[self ViewInScrollView] frame].size];
}
#end
ImagesViewController's xib is a view, 768 wide by 200 tall (I made an iPad-based UITableView single-view application). Inside its view is a UIScrollView, set to take up the entire [view frame] area. Then I put a UIView inside of it.
My testing gives me a header that is an orange rectangle, and I can scroll it around as you would expect. This leads me to believe that maybe you need to check the shocks/struts of your imagesScrollView in Interface Builder. Make sure all of the margins and widths are fixed/flexible as you need for it to display properly.

Changed nib File to a OPGL ES View, Buttons don't work

Hy,
There is no problmen with changing the nib but when I'm in the nib-File with the OPGL ES view my buttons that are integrated in this view won't work. When I press one the application crashes.
This is the Code how I change the View to the Second Nib:
- (IBAction)drawEAGLView:(id)sender {
NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:#"settingsViewController" owner:self options:nil];
EAGLView* glView = [ nibViews objectAtIndex: 1];
self.view = glView;
[glView startAnimation];}
The Animation is working .
This is the Code of the ViewController where the Button is declared:
SettingsViewController.h:
#import <UIKit/UIKit.h>
#interface SettingsViewController : NSObject {
IBOutlet UIButton *wowButton;
}
#property(nonatomic,retain) IBOutlet UIButton *wowButton;
- (IBAction)wowButtonPressed:(id)sender;
int testvarAnimation;
int animNext;
#end
SettingsViewController.m:
#import "SettingsViewController.h"
#implementation SettingsViewController
#implementation SettingsViewController
#synthesize wowButton;
- (IBAction)wowButtonPressed:(id)sender{
NSLog(#"TOUCHED");
//testvarAnimation = 1;
animNext =1;
}
- (void)dealloc {
[wowButton release];
[super dealloc];
}
#end
Here I show you how I connected the Functions and the Outlets:
http://s3.imgimg.de/uploads/screenshotConna91ea645png.png
Please tell me If you need more informations.
Thanks
Hy I solved my problem, I rewrote my drawEAGLView Methode:
- (IBAction)drawEAGLView:(id)sender {
SettingsViewController *sViewController = [[SettingsViewController alloc] initWithNibName:#"SettingsViewController" bundle:nil];
[[self.view superview] addSubview:sViewController.view];
}
I also corrected my SettingsViewController.h:
#import <UIKit/UIKit.h>
#class EAGLView;
#interface SettingsViewController : UIViewController {
IBOutlet UIButton *wowButton;
EAGLView *glview;
}
#property(nonatomic,retain) IBOutlet UIButton *wowButton;
#property (nonatomic, retain) IBOutlet EAGLView *glView;
- (IBAction)wowButtonPressed:(id)sender;
int testvarAnimation;
int animNext;
#end
And last but not least I changed my SettingsViewController.m:
#import "SettingsViewController.h"
#import "EAGLView.h"
#implementation SettingsViewController
#synthesize wowButton, glView;
- (IBAction)wowButtonPressed:(id)sender{
NSLog(#"TOUCHED");
//testvarAnimation = 1;
animNext =1;
}
- (void)viewDidLoad {
glView.animationInterval = 1.0 / 60.0;
[glView startAnimation];
[super viewDidLoad];
}
- (void)dealloc {
[wowButton release];
[super dealloc];
}
#end
I also changed my Nib file. I removed the ViewController and set the type of the File's Owner to my viewController named "SettingsViewController". I connected the File's Owner Outlet view with the EAGLView and the button with the SettingsViewControllers wowButtonPressed Method
I hope I could help also someone else,
Thanks
Here is the right solution for this problem:
First you have to create a parnet object of your view you want to be shown as first.
You need to do this in the header file of the second view.
//
// SettingsViewController.h
// NeheTutorial2
//
// Created by Global Sound on 05.04.11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
#class EAGLView;
#class mobilesynthViewController;
#interface SettingsViewController : UIViewController {
IBOutlet UIButton *wowButton;
IBOutlet UIButton *optiButton;
EAGLView *glView;
//mobilesynthViewController *mViewController;
mobilesynthViewController *parent;
}
#property(nonatomic,retain) IBOutlet UIButton *wowButton;
#property(nonatomic,retain) IBOutlet UIButton *optiButton;
#property (nonatomic, retain) IBOutlet EAGLView *glView;
//#property(nonatomic,retain) IBOutlet mobilesynthViewController *mViewController;
#property (nonatomic, retain) mobilesynthViewController *parent;
- (IBAction)wowButtonPressed:(id)sender;
- (IBAction)optiButtonPressed:(id)sender;
int testvarAnimation;
int animNext;
int musicOn;
int isAnimating;
float zaehler;
#end
Now in the implemetaion File you need to add the parent object to your function:
#import "SettingsViewController.h"
#import "EAGLView.h"
//#import "mobilesynthViewController.h"
#implementation SettingsViewController
#synthesize wowButton, optiButton, glView;//,mViewController;
#synthesize parent;
- (IBAction)wowButtonPressed:(id)sender{
NSLog(#"TOUCHED");
[parent startThread];
[parent showbButtonStop];
testvarAnimation = 0;
animNext =1;
//musicOn =1;
}
- (IBAction)optiButtonPressed:(id)sender{
NSLog(#"OPTIONS ON");
[self dismissModalViewControllerAnimated:YES];
[parent showbButton];
//mobilesynthViewController *aRootViewController = [[mobilesynthViewController alloc] initWithNibName:#"mobilesynthViewContoller" bundle:nil];
//[self setRootViewController:aRootViewController];
//[aRootViewController release];
//mobilesynthViewController *mViewController = [[mobilesynthViewController alloc] initWithNibName:#"mobilesynthViewController" bundle:nil];
//[[self.view superview] addSubview:mViewController.view];
//self.view = mViewController;
//CGRect rect = [[UIScreen mainScreen] applicationFrame];
//mViewController = [[mobilesynthViewController alloc] initWithFrame:CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)];
//self.view = mViewController;
}
- (void)viewDidLoad {
glView.animationInterval = 1.0 / 60.0;
[glView startAnimation];
[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 {
[wowButton release];
[optiButton release];
[super dealloc];
}
#end
In my case I'm calling a other function in the main View of my program. When the button in the second view is pressed the function in the first view is called through the the parent object
[parent startThread];
Again the startThread methode was declerated in another view.
I hope I could help you.

iPhone - creating a loading view

When the app is in one view controller, I want to add a view to simulate that data is being loaded when I click my tab bar controller to open another view controller.
Example: When I the app is in the recorder-view, I want it to show a loading view (a view with a activity indicator) when I change to the list of recorded files (which can take some time to load). I've tried manipulate this with the viewWillDisappear-event, but I can't get it to work - the view is not being added before after the viewDidAppear-event occurs.
Anyone have any thoughts regarding this?
Thanks
Thank you for your reply. I tried doing like tou suggested, but I still can't get it to show when I want. I try to set hidden = NO in my viewWillDisappear-event, but it does not show before that view controller disappears and the next one appears
Right now it sounds like you have a UITabBarController That takes up the whole screen. What I would do is put the loading view above the TabBarController and hide it when not necessary. I would create a subclass of loadingViewController in the same xib your tab bar controller came from (or programatically if you desire) and set it to an IBOutlet of the App Delegate.
Something like this:
//In your App Delegate
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:tabBarController.view];
loadingView.hidden = YES;
[window insertSubview:loadingViewController.view aboveSubview:abBarController.view];
[window makeKeyAndVisible];
}
//In your loading View Controller
- (void) setLoadingViewHidden:(BOOL)hidden {
self.view.hidden = hidden;
self.activityIndicator.animating = hidden;
}
The way I've done this in the past is to have a content view which houses either an activity view or the view proper.
In the view controller's nib, instead of adding subviews to the main view, leave it empty and create a new view (such as a table view in the example below) for the view proper.
Also create an activity view (with a threaded progress indicator or somesuch) and a "no results" view.
Then derive your controller class from the something like the following:
//
// ContainerViewController.h
//
#import <UIKit/UIKit.h>
#interface ContainerViewController : UIViewController
{
UIView *myContainerView;
UITableView *myTableView;
UIView *mySearchActivityView;
UIView *myZeroResultsView;
UIView *myCurrentlyShowingView;
}
#property (retain, nonatomic) IBOutlet UIView *containerView;
#property (retain, nonatomic) IBOutlet UITableView *tableView;
#property (retain, nonatomic) IBOutlet UIView *searchActivityView;
#property (retain, nonatomic) IBOutlet UIView *zeroResultsView;
#property (assign) UIView *currentlyShowingView;
#end
//
// ContainerViewController.m
//
#import "ContainerViewController.h"
#implementation ContainerViewController
#synthesize containerView = myContainerView;
#synthesize tableView = myTableView;
#synthesize searchActivityView = mySearchActivityView;
#synthesize zeroResultsView = myZeroResultsView;
- (void)dealloc
{
[myContainerView release], myContainerView = nil;
[myTableView release], myTableView = nil;
[mySearchActivityView release], mySearchActivityView = nil;
[myZeroResultsView release], myZeroResultsView = nil;
myCurrentlyShowingView = nil;
[super dealloc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.currentlyShowingView = mySearchActivityView;
mySearchActivityView.backgroundColor = [UIColor clearColor];
myZeroResultsView.backgroundColor = [UIColor clearColor];
}
- (void)setCurrentlyShowingView:(UIView *)view
{
[myCurrentlyShowingView removeFromSuperview];
CGRect frame = view.frame;
frame.size = myContainerView.frame.size;
view.frame = frame;
[myContainerView addSubview:view];
myCurrentlyShowingView = view;
if (view == myTableView)
[myTableView reloadData];
}
- (UIView *)currentlyShowingView
{
return myCurrentlyShowingView;
}
#end
And in the -viewDidLoad method of the derived class, set off the (asynchronous) query:
- (void)viewDidLoad
{
[super viewDidLoad];
myQueryLoader = [[QueryLoader alloc] initWithQuery:#"whatever" delegate:self];
self.currentlyShowingView = mySearchActivityView;
}
and in the delegate callback:
- (void)queryLoader:(QueryLoader *)queryLoader didEndWithResults:(id)results error:(NSError *)error
{
myItems = [results retain];
if (myItems)
self.currentlyShowingView = myTableView;
else
self.currentlyShowingView = myZeroResultsView;
}
Hope this helps!