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 09-07-2010, 01:05 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: UK, North East
Posts: 227
zardon is on a distinguished road
Default Releasing UIBarButtonItem for UINavController

I have a UINavigationController which allows you to go from 1 screen to the other. There are only 2 screens at the moment.

On the second screen, there is a toolbar with 2 buttons put on the right hand side.

The problem I'm having is when I go back to the previous screen one of two things happens.

1. The app does not go back to the previous screen and it will simply dump to the iphone home screen (quits the app altogether).

2. I know that it is a memory issue and have pinpointed it to UIBarButton allocation. Now, if I remove the release the screen movement is fine; but it causes a memory leak.

I've tried adding autorelease to my UIBarButton call but this causes the app to dump out.

I've tried creating a temp pointer to the UIBarButton then releasing once it has been used; but this causes the same problem.

If I remove all references to releasing UIBarButton all navigation is fine, but it causes a memory leak problem.

I seem to be going around in circles.

Code:
// This is on SecondViewController;
- (void)viewDidLoad 
{
	[super viewDidLoad];

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;


	// Toolbar
	UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 100.0, 44.01)];
	
	// Create array for buttons	
	NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:2];
	
	// Create buttons
	UIBarButtonItem *btnAdd = [[UIBarButtonItem alloc] 
							   initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
							   target:self action:@selector(btnAdd:)];
	
	btnAdd.style = UIBarButtonItemStyleBordered;
	
	UIBarButtonItem *btnEdit = self.editButtonItem;
	
	// Add to buttons array
	[buttons addObject:btnAdd];
	[buttons addObject:btnEdit];
	
	// Set the buttons to toolbar
	[toolbar setItems:buttons];
		
	UIBarButtonItem *tmp = [[[UIBarButtonItem alloc] initWithCustomView:toolbar] autorelease];
	
	// Add toolbar to the right bar
	self.navigationItem.rightBarButtonItem = tmp;
	
	// Memory cleanup
	[buttons release];
	[btnAdd release];
	[btnEdit release];
	[toolbar release];
	//[tmp release];
	
	
}
Has anyone come across this problem before, and if so; how did you resolve it?

Thanks
zardon is offline   Reply With Quote
Old 09-07-2010, 01:23 PM   #2 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: UK, North East
Posts: 227
zardon is on a distinguished road
Default

I figured out the problem after going through the viewDidLoad one line at a time.

It turns out it was:

[btnEdit release];

That was causing the problem because it was never allocated in the first place.

I did a check on leaks and it seems to be fine now.

I hate it when its just small things like this that cause problems; it makes me wonder if I'll ever get the app I want done, well done.
zardon is offline   Reply With Quote
Reply

Bookmarks

Tags
memory leaks, memory man, uibarbuttonitem

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: 334
11 members and 323 guests
bignoggins, carlandrews, flamingliquid, hzwegjxg, ilmman, jenniead38, linkmx, nadav@webtview.com, stanny, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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