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 10-12-2010, 10:43 AM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 551
aldcorn@live.com is on a distinguished road
Default UIBarButtonItem custom editButton

How do I find out what method is used here:
Code:
self.navigationItem.rightBarButtonItem = self.editButtonItem;
I have created a custom button and I want it to act like the editButtonItem. I do not know how to do this. The code below is what I am using. All of my custom buttons are showing up but I do not know what I should use in the @selector(...?..

I want my custom editButton to work like the default editButton

Code:
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,100,45)];
[toolBar setBarStyle:UIBarStyleBlackOpaque];
	
NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:3];
	
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)];
addButton.style = UIBarButtonItemStyleBordered;
[buttons addObject:addButton];
[addButton release];
	
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace 
													target:self action:nil];
[buttons addObject:spacer];
[spacer release];
	
UIBarButtonItem *editButton = [[UIBarButtonItem alloc]

//what should I use in the following @selector?...
initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(:)];
editButton.style = UIBarButtonItemStyleBordered;
[buttons addObject:editButton];

[editButton release];
	
	
[toolBar setItems:buttons animated:NO];
[buttons release];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolBar];
Thanks for having a look,
Rob

Last edited by aldcorn@live.com; 10-12-2010 at 10:48 AM.
aldcorn@live.com is offline   Reply With Quote
Old 10-12-2010, 11:15 AM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Just use the editButtonItem. As noted in the documentation, it calls setEditing:animated:
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 10-12-2010, 11:45 AM   #3 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 551
aldcorn@live.com is on a distinguished road
Default subclassed so I can have three buttons on navigation bar

Hi Brian,
Thanks for the reply.
Because I am creating a subview toolBar in the rightBarButtonItem I can not seem to get the edit button to work there. If I simply use the self.navigationItem.rightBarButtonItem = self.editButtonItem it works but I do not know how to create that editButtonItem in the subview I guess...


I am trying to have three buttons in the navigation bar. Back, add and edit. The back and add buttons are working as expected and the edit button shows up but does not do anything.

Quote:
Originally Posted by BrianSlick View Post
Just use the editButtonItem. As noted in the documentation, it calls setEditing:animated:

Last edited by aldcorn@live.com; 10-12-2010 at 11:47 AM.
aldcorn@live.com is offline   Reply With Quote
Old 10-12-2010, 11:52 AM   #4 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 551
aldcorn@live.com is on a distinguished road
Default I think I got it.

Thanks for your help Brian.
For anyone following this thread the solution for me was to simply rename my editButton to editButtonItem in all spots. Everything appears to be working as expected now.

Take care,
Rob


Quote:
Originally Posted by BrianSlick View Post
Just use the editButtonItem. As noted in the documentation, it calls setEditing:animated:
aldcorn@live.com is offline   Reply With Quote
Old 10-12-2010, 12:08 PM   #5 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 551
aldcorn@live.com is on a distinguished road
Default Not out of the woods yet !

Hi,
To follow this process I am now successfully getting the EDIT mode but my EDIT button is not changing to DONE during the editing process. How do I go about resolving this?

Thanks,
Rob
aldcorn@live.com is offline   Reply With Quote
Old 10-12-2010, 12:46 PM   #6 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

You have to call [super setEditing...] in the method.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 10-12-2010, 01:21 PM   #7 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 551
aldcorn@live.com is on a distinguished road
Default I think I am calling it.

Hi,
As far as I understand this I think I am calling this method for my setEditing:
Code:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
	[super setEditing:editing animated:animated];
	
	self.navigationItem.hidesBackButton = editing;
	
	//call on each section controller
	for (id<CDLTableSectionControllerProtocol> sectionController in self.sectionControllers) {
		[sectionController setEditing:editing animated:animated];
	}
	
	[self.tableView reloadData];
}
????help...

Quote:
Originally Posted by BrianSlick View Post
You have to call [super setEditing...] in the method.
aldcorn@live.com is offline   Reply With Quote
Old 10-12-2010, 01:24 PM   #8 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Post your new version of the method in the first post. Post the entire method.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 10-12-2010, 01:40 PM   #9 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 551
aldcorn@live.com is on a distinguished road
Default

Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,100,45)];
	[toolBar setBarStyle:UIBarStyleBlackOpaque];
NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:3];
	
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)];
addButton.style = UIBarButtonItemStyleBordered;
[buttons addObject:addButton];
[addButton release];
	
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace 
target:self action:nil];
[buttons addObject:spacer];
[spacer release];
	
UIBarButtonItem *editButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemEdit 
target:self action:@selector(setEditing:animated:)];
	
editButtonItem.style = UIBarButtonItemStyleBordered;
[buttons addObject:editButtonItem];
[editButtonItem release];
	
[toolBar setItems:buttons animated:NO];
[buttons release];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolBar];
		
if (_fullyLoaded) { //only try to load the objects if we have loaded from a plist
	NSError *error;
	//get the intial results back from the fetchedresultscontroller
	if (![[self fetchedResultsController] performFetch:&error]) {
	[[DataController sharedDataController] handleError:error fromSource:@"CDLRootViewController - viewDidLoad - performFetch"];
		}
	}
Quote:
Originally Posted by BrianSlick View Post
Post your new version of the method in the first post. Post the entire method.
aldcorn@live.com is offline   Reply With Quote
Old 10-12-2010, 01:43 PM   #10 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Yeah, you just named it editButtonItem, but you aren't actually using THE editButtonItem. You should.

Also, this is a leak:

Code:
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolBar];
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 10-12-2010, 01:54 PM   #11 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 551
aldcorn@live.com is on a distinguished road
Default I do see that I am creating an instance but...

I am not sure how to do this...

Quote:
Originally Posted by BrianSlick View Post
Yeah, you just named it editButtonItem, but you aren't actually using THE editButtonItem. You should.

Also, this is a leak:

Code:
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolBar];
aldcorn@live.com is offline   Reply With Quote
Old 10-12-2010, 01:56 PM   #12 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

What do you mean you don't know how?

Quote:
Originally Posted by aldcorn@live.com View Post
If I simply use the self.navigationItem.rightBarButtonItem = self.editButtonItem
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 10-12-2010, 02:04 PM   #13 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 551
aldcorn@live.com is on a distinguished road
Default

Are you suggesting that I avoid the use of this toolBar subView?

You are correct that I know how to get the editButtonItem to work when it is the rightBarButtonItem but When I add another button into the rightBarButtonItem as subviews I don't know how to add THE editButtonItem.

I can understand your frustration here and I appreciate your help.

Quote:
Originally Posted by BrianSlick View Post
What do you mean you don't know how?
aldcorn@live.com is offline   Reply With Quote
Old 10-12-2010, 02:05 PM   #14 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Code:
[buttons addObject:[self editButtonItem]];
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 10-12-2010, 02:08 PM   #15 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 551
aldcorn@live.com is on a distinguished road
Default Oh!! Button works but my leak is still leaking.

Hi Brian,
I do seem to have implemented this successfully:

[buttons addObject:self.editButtonItem];


My leak:
I tried:
autorelease

Can you point me in the right direction again?

Thanks,
Rob

Quote:
Originally Posted by BrianSlick View Post
What do you mean you don't know how?
aldcorn@live.com is offline   Reply With Quote
Old 10-12-2010, 02:11 PM   #16 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Posting portions of a line of code is not useful. Post the entire line if you're going to post something.

But yes, autoreleasing the button would avoid the leak.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 09-13-2011, 12:52 AM   #17 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 2
anilvooty is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Posting portions of a line of code is not useful. Post the entire line if you're going to post something.

But yes, autoreleasing the button would avoid the leak.
I am trying to do something similar. Following is my problem, can someone please help

I have added uitoolbar in uinavigationcontroller using IB (by selecting the check box - "show toolbar"). I used IB since this was easy to add flexible spacing bar buttons (I did not want to deal with spacing code programmatically). My issue is that I want to invoke the built-in edit and add functionality for the 2 toolbar buttons I added. I know that in the navigation bar I can use the following code and it will invoke this functionality

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemA dd target:self action:nil];
Above code takes care of the "Edit view", where the table view items are shown with a delete button next to them.

How can I achieve the same for the buttons that I added to the toolbar? I am using Xcode 4. Please point me to some code examples.
anilvooty is offline   Reply With Quote
Reply

Bookmarks

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: 354
10 members and 344 guests
alexP, gordo26, headkaze, mistergreen2011, nobstudio, Objective Zero, rayjeong, revg, Sloshmonster, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

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