Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-11-2011, 05:22 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 16
trembler is on a distinguished road
Default View disappears when going back into app then tabs go too

Hi,

First post on the forums but been on here a while. I'm writing my first App and coming pretty near to completion now but got a fairly big bug that can't solve so far.

SDK/iPhone details: XCode 3.2, iOS 4.2 SDK, iPhone 3GS 16GB with iOS 4.33 installed. This bug also happened when I had 4.0 installed on the phone. I can't repeat at the moment in the iPhone Simulator.

Structure wise my app has:

- AppDelegate application function loads up a UITabBarController with two tabs in - each displaying a UIViewController when clicked. AppDelegate also has a member UINavigationController
- The first tab has a UITableViewController in showing my apps "User list" along with the delegate's NavigationController showing at the top
- When you tap on a user, a "UserDetail" UIViewController is pushed on to the NavController.
- The UserDetail view has a UITabBar at the bottom with 6 UITabBarItems in. Tapping on each one will add a different subview - each being a UIViewController. Also up the top is a right-navbarbutton that pushes another UIViewController onto the NavController (so essentially 3 levels down now)

So essentially, it's a 2 tabs on the first screen and then 6 tabs on the next screen level down.

The problem I'm having is that if click the iPhone's home button and leave the app, then go back to the app after a while - when I tap on a user on the first screen, the 6-tab bar is shown at the bottom but the view above isn't displayed - its blank. Then if I tap the right-navbar-button at the top and go to the third level down and then back again - the view has now appeared but my tabs (the 6-tabs) have gone and never come back until I shut the app down and go back in.

Has anyone ever seen this kind of thing before and know where I should look or what more information I could provide to help get an answer?

Cheers

Chris
trembler is offline   Reply With Quote
Old 06-14-2011, 04:12 PM   #2 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 16
trembler is on a distinguished road
Default

Anyone know anything I can do to try and solve this? I'm getting a little desperate :-)
trembler is offline   Reply With Quote
Old 06-16-2011, 05:13 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 16
trembler is on a distinguished road
Default

Hi... I have a bit more info... I now know this is happening after a memory warning to my app and so have now managed to repeat in the simulator with the hardware->simulate memory warning option (I didn't know it was there until now)...

So, now I'm trying to debug through the ViewController that's giving me the problem but still not getting very far, so I thought I'd post the code below (sanitised so its not obvious what I'm writing) of the particular ViewController...

I'm aware I'm currently not doing anything in didReceiveMemoryWarning or viewDidUnload but I'm not quite sure what I need to do for these - any pointers based on the rest of the ViewController would be great...

.h file:

Code:
//
//  UserDetailViewController.h
//  myAppTracker2
//
//  Created by Chris Tromans on 24/02/2011.
//  Copyright 2011 None. All rights reserved.
//

#import <UIKit/UIKit.h>
@class UserSummaryViewController;



@interface UserDetailViewController : UIViewController <UITabBarDelegate> {
	IBOutlet UITabBar *inputTypeTabBar;
	IBOutlet UITabBarItem *oneTabBarItem;
	IBOutlet UITabBarItem *twoTabBarItem;
	IBOutlet UITabBarItem *threeTabBarItem;
	IBOutlet UITabBarItem *fourTabBarItem;
	IBOutlet UITabBarItem *fiveTabBarItem;
	IBOutlet UITabBarItem *sixTabBarItem;
	
	NSArray *viewControllers;
	
	UIViewController *selectedViewController;
	
	UserSummaryViewController *userSummaryViewController;


}
@property (nonatomic, retain) UITabBar *inputTypeTabBar;
@property (nonatomic, retain) UITabBarItem *oneTabBarItem;
@property (nonatomic, retain) UITabBarItem *twoTabBarItem;
@property (nonatomic, retain) UITabBarItem *threeTabBarItem;
@property (nonatomic, retain) UITabBarItem *fourTabBarItem;
@property (nonatomic, retain) UITabBarItem *fiveTabBarItem;
@property (nonatomic, retain) UITabBarItem *sixTabBarItem;
@property (nonatomic, retain) NSArray *viewControllers;
@property (nonatomic, retain) UIViewController *selectedViewController;
@property (nonatomic, retain) UserSummaryViewController *userSummaryViewController;


- (void)viewSummary:(id)sender;


@end
.m file

Code:
//
//  UserDetailViewController.m
//  MyAppTracker2
//
//  Created by Chris Tromans on 24/02/2011.
//  Copyright 2011 None. All rights reserved.
//

#import "UserDetailViewController.h"
#import "OneEntryViewController.h"
#import "TwoEntryViewController.h"
#import "ThreeEntryViewController.h"
#import "FourEntryViewController.h"
#import "FiveEntryViewController.h"
#import "SixEntryViewController.h"
#import "MyAppTracker2AppDelegate.h"


@implementation UserDetailViewController

@synthesize inputTypeTabBar;
@synthesize OneTabBarItem;
@synthesize TwoTabBarItem;
@synthesize ThreeTabBarItem;
@synthesize FourTabBarItem;
@synthesize fivesTabBarItem;
@synthesize SixTabBarItem;
@synthesize viewControllers;
@synthesize selectedViewController;
@synthesize userSummaryViewController;



// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
		OneEntryViewController *OneController = [[OneEntryViewController alloc] initWithNibName:@"OneEntryViewController" bundle:nil];
		TwoEntryViewController *TwoController = [[TwoEntryViewController alloc] initWithNibName:@"TwoEntryViewController" bundle:nil];
		ThreeEntryViewController *ThreeController = [[ThreeEntryViewController alloc] initWithNibName:@"ThreeEntryViewController" bundle:nil];
		FourEntryViewController *FourController = [[FourEntryViewController alloc] initWithNibName:@"FourEntryViewController" bundle:nil];
		FiveEntryViewController *FiveController = [[FiveEntryViewController alloc] initWithNibName:@"FiveEntryViewController" bundle:nil];
		SixEntryViewController *SixController = [[SixEntryViewController alloc] initWithNibName:@"SixEntryViewController" bundle:nil];

		NSArray *array = [[NSArray alloc] initWithObjects: OneController, TwoController, ThreeController, FourController, FiveController, SixController, nil];
		self.viewControllers = array;
		
		[self.view addSubview:OneController.view];
		self.selectedViewController = OneController;
		
		[array release];
		[OneController release];
		[TwoController release];
		[ThreeController release];
		[FourController release];
		[FiveController release];
		[SixController release];
		
    }
    return self;
}


- (void)viewDidAppear:(BOOL)animated
{
	
}




// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	
	inputTypeTabBar.selectedItem = OneTabBarItem;
	
	self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Summary" style:UIBarButtonItemStylePlain target:self action:@selector(viewSummary:)];
	
    [super viewDidLoad];
}

- (void)viewSummary:(id)sender
{
	if ( self.userSummaryViewController == nil )
	{
		UserSummaryViewController *userSummary = [[UserSummaryViewController alloc] initWithNibName:@"UserSummaryViewController" bundle:nil];
		self.userSummaryViewController = userSummary;
		[userSummary release];
	}
	
	MyAppTracker2AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
	
	[delegate.usersRootNavController pushViewController:userSummaryViewController animated:YES];
}



- (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 {
	
	[inputTypeTabBar release];
	[OneTabBarItem release];
	[TwoTabBarItem release];
	[ThreeTabBarItem release];
	[FourTabBarItem release];
	[fivesTabBarItem release];
	[SixTabBarItem release];
	[viewControllers release];
	[selectedViewController release];
	[userSummaryViewController release];
    [super dealloc];
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
	if ( item == OneTabBarItem )
	{
		
		UIViewController *OneController = [viewControllers objectAtIndex:0];
		[self.selectedViewController.view removeFromSuperview];
		[self.view addSubview:OneController.view];
		self.selectedViewController = OneController;
	}
	else if (item == TwoTabBarItem )
	{
		UIViewController *TwoController = [viewControllers objectAtIndex:1];
		[self.selectedViewController.view removeFromSuperview];
		[self.view addSubview:TwoController.view];
		self.selectedViewController = TwoController;
	}
	else if (item == ThreeTabBarItem )
	{
		UIViewController *ThreeController = [viewControllers objectAtIndex:2];
		[self.selectedViewController.view removeFromSuperview];
		[self.view addSubview:ThreeController.view];
		self.selectedViewController = ThreeController;
	}
	else if (item == FourTabBarItem )
	{
		UIViewController *FourController = [viewControllers objectAtIndex:3];
		[self.selectedViewController.view removeFromSuperview];
		[self.view addSubview:FourController.view];
		self.selectedViewController = FourController;
	}
	else if (item == fivesTabBarItem )
	{
		UIViewController *fivesController = [viewControllers objectAtIndex:4];
		[self.selectedViewController.view removeFromSuperview];
		[self.view addSubview:fivesController.view];
		self.selectedViewController = fivesController;	
	}
	else if (item == SixTabBarItem )
	{
		UIViewController *SixController = [viewControllers objectAtIndex:5];
		[self.selectedViewController.view removeFromSuperview];
		[self.view addSubview:SixController.view];
		self.selectedViewController = SixController;
	}
}
	 



@end
trembler is offline   Reply With Quote
Old 06-17-2011, 12:43 PM   #4 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 2
Patrick181818 is on a distinguished road
Default

Hi!!! I saw your code and I have one dubts or two.

OneController is the view that content de tabbarButtons? And when you change view do [self.selectedViewController.view removeFromSuperview] you remove one controller and put the new view? I dont understand this part and if you have 5 or 6 SUBViews.

Thnks for all and sorry for my English haha
Patrick181818 is offline   Reply With Quote
Old 06-17-2011, 06:03 PM   #5 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Seattle, WA
Posts: 408
RickSDK is on a distinguished road
Default

not exactly sure what problem you are having, but any time i am getting weird behavior like that, I comment out all the [release] lines of code and try running it again. this might help you isolate the problem. if you are releasing something at the wrong time, you app may behave very badly.

You can also force your app to always start at the first screen by checking the "Application does not run in backgr" flag in your info.plist file.
RickSDK is offline   Reply With Quote
Old 06-18-2011, 04:16 AM   #6 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 16
trembler is on a distinguished road
Default

Thanks to those who replied. Rich - I did take your "app does not run in background" route to start with today but then had a brainwave as to what it might be doing and found a solution.

I opened the xib of the first tab view and it hadn't got a bottom bar set to be a tab-bar (so it was covering the tabs when going back into the app) so I set that and then on first draw it appeared to high. So I moved the first subview add from the initWithNibName down to inside the viewDidLoad instead and wrapped it in a nil check on self.selectedViewController - I also had to force the frame of this first subView add to stop it appearing too high:

Code:
      if ( self.selectedViewController == nil )
      {
                OneController.view.frame = CGRectMake(0,0,320,411);
		[self.view addSubview:OneController.view];
		self.selectedViewController = OneController;
       }
I then added the following line to the didReceiveMemoryWarning in this ViewController so that I knew the subView had been automatically removed and I'd have to add it again - as that was why it was appearing blank when re-opening the app:

Code:
               self.selectedViewController = nil;

Seems to have finally solved the problem... now onto the last steps to release the app at last...
trembler is offline   Reply With Quote
Old 06-21-2011, 05:39 AM   #7 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 2
Patrick181818 is on a distinguished road
Default

The problem here is if you want return to the view. If you click the TabBar Item and change view, then you cant return =(
Patrick181818 is offline   Reply With Quote
Reply

Bookmarks

Tags
blank view, uitabbar, uiviewcontroller

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 313
6 members and 307 guests
chemistry, Dnnake, iOS.Lover, lendo, Leslie80, pbart
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:22 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0