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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 03-02-2010, 01:10 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Wien/Austria
Posts: 242
Default Disable/Hide UIBarButtonItem

Hi,

In my App I use the call function to make a phone call! Apple rejected my app now, because I havenīt hidden or disabled the Call Button if a User has an Ipod Touch...

Fetch the Platform

Code:
-(NSString*)getPlatformName {
	size_t size;  
	sysctlbyname("hw.machine", NULL, &size, NULL, 0);  
	char *machine = (char*)malloc(size);  
	sysctlbyname("hw.machine", machine, &size, NULL, 0);  
	NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];
	free(machine);
	
	return platform;
}
Code:
-(void)viewWillAppear:(BOOL)animated {
	
	NSString * platform = [self getPlatformName];
	
	if ([platform isEqualToString:@"i386"]) {
		// do simulator-specific stuff, perhaps enable a more verbose level of logging?
		NSLog(@"i386");
		[callButton.hidden:NO]; 

	}
	else if ([platform isEqualToString:@"iPod2,1"]) {		
		// do iPod-specific stuff, perhaps disable UI that refers to GPS, vibration, etc.
		
		NSLog(@"iPod");
	}
	else if ([platform isEqualToString:@"iPhone2,1"]) {
		// do iPhone 3GS-specific stuff, perhaps compass related?
		NSLog(@"iPhone");
	}
}
Code:
- (IBAction)call {
	
	NSLog(@"bin im Call");
	
	
	UIApplication *app = [UIApplication sharedApplication];
	//NSString *dialThis = (@"tel:%@", alertPersonPhone);
	NSString *urlString = [NSString stringWithFormat:@"tel:%@", phone];
	
	NSLog(@"die Telefonnummer: %@", urlString);
	
	NSURL *url = [NSURL URLWithString:urlString];
	[app openURL:url];
	
}
callButton is the name of the BarButtonItem - how can I disable or hide it?

Thanks for your feedback,

Stefan
StefanL is offline   Reply With Quote
Old 03-02-2010, 01:25 PM   #2 (permalink)
Registered Member
 
Join Date: May 2009
Location: Denver CO
Posts: 88
Default

This is how I implemented the exact same thing.
Have a call button, but only if it's an iPhone
Code:
NSString *deviceType = [UIDevice currentDevice].localizedModel;
	if ([deviceType isEqualToString:@"iPhone"]) {
		//if it's an iPhone, great - add the button to the bar
	}else {
		//if you have something else you would like to put there instead....
	}
seriessix is offline   Reply With Quote
Old 03-02-2010, 01:41 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Wien/Austria
Posts: 242
Default

Hi Seriesix,

it is the same - I also want to hide the BarButtonItem when it is Ipod... But I am not sure how to disable/hide the BarButtonItem

callButton.hidden: YES;

callButton.enabled = NO;

is not working...

BR,

Stefan
StefanL is offline   Reply With Quote
Old 03-02-2010, 03:39 PM   #4 (permalink)
Registered Member
 
Join Date: May 2009
Location: Denver CO
Posts: 88
Default

I would say, do not add the button in IB. If you add it programmatically, you can just not add it if the device is not of the right type. Enabled and hidden don't work on bar buttons as far as I am aware.
seriessix is offline   Reply With Quote
Old 03-02-2010, 03:50 PM   #5 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 791
Default

Suppose you have an IBOutlet for your toolbar, and an IBOutlet for your UIBarButtonItem, you can do it like this on your viewDidLoad:

Code:
NSMutableArray *items = [myToolBar.items mutableCopy];
[items removeObject:myButton];
toolBar.items = items;
[items release];
nobre84 is offline   Reply With Quote
Old 06-15-2010, 05:31 AM   #6 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 1
Default Disabele/Hide of UIBarButtonItem

Hi,
suppose you have a done button of UIBarButtonItem and u want to hide it and show it programmatically depends upon your requirement.so you have do like following...

To Hide:

Declaration

UIBarButtonItem *donebutton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemD one target:self action:@selector(ondoneButtonPressed)];

self.navigationItem.rightBarButtonItem = donebutton;

for hide:

self.navigationItem.rightBarButtonItem = nil;

To Show:simply call
self.navigationItem.rightBarButtonItem = donebutton;

It will work for UIBarButtonItem , donebutton.hidden=YES will not work.
You can enable/disable by simply writing donebutton.enable=YES/NO.

Do not know about in which iphone environment for u r working but the given code will work for hiding and showing the UIBarButton for requirements in ur program.

swarnalata

Last edited by swarnalata; 06-15-2010 at 05:34 AM.
swarnalata is offline   Reply With Quote
Old 01-07-2011, 07:46 PM   #7 (permalink)
Registered Member
 
Join Date: Apr 2010
Location: Rome, IT
Posts: 98
Default

I have the same need and i solved with a simple solution.
In my code i just enable/disable a UIBarButtonItem.
I declared an IBOutlet in my .h file

Code:
IBOutlet UIBarButtonItem *my_button;
In IB i linked the button with my previous declaration and within the .m file i do

Code:
//to disable
[my_button setEnabled:FALSE];

//to enable
[my_button setEnabled:TRUE];
Seems work fine

Ciao,
saluti
skunkio is offline   Reply With Quote
Old 05-17-2011, 04:52 AM   #8 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 90
Default

Quote:
Originally Posted by skunkio View Post
I have the same need and i solved with a simple solution.
In my code i just enable/disable a UIBarButtonItem.
I declared an IBOutlet in my .h file

Code:
IBOutlet UIBarButtonItem *my_button;
In IB i linked the button with my previous declaration and within the .m file i do

Code:
//to disable
[my_button setEnabled:FALSE];

//to enable
[my_button setEnabled:TRUE];
Seems work fine

Ciao,
saluti
What about to hide? how we can hide UIBarButtonItem?

Any idea ?
iphone.savvy is offline   Reply With Quote
Reply

Bookmarks

Tags
call, platform, 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: 317
19 members and 298 guests
@sandris, ADY, dacapo, Dani77, djohnson, dre, HDshot, HemiMG, JasonR, MarkC, mer10, nibeck, prchn4christ, ryandb2, spiderguy84, timle8n1, tomtom100, vogueestylee
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

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