Skip to content

Instantly share code, notes, and snippets.

@Jarada
Created May 20, 2012 18:48
Show Gist options
  • Save Jarada/2759118 to your computer and use it in GitHub Desktop.
Save Jarada/2759118 to your computer and use it in GitHub Desktop.
myLauncher moving close barbuttonitem
// This is an example coding gist for use on myLauncher Google Groups to explain how to move the close icon used to close a launched item in code
/*
ItemViewController - represents the View Controller of the item that is launched when the icon is tapped
We modify the navigation item on ViewLoad to move the barButtonItem to the right
We then pass this the barButtonItem on
*/
@implementation ItemViewController
-(void)viewDidLoad {
// Add this to the bottom of the method to move the close button to the right
// The if prevents this code executing on anything but the first screen
if (!self.navigationItem.rightBarButtonItem) {
[self.navigationItem setRightBarButtonItem:self.navigationItem.leftBarButtonItem];
[self.navigationItem setLeftBarButtonItem:nil];
}
}
-(void)openView {
UIViewController *targetViewController = [[ItemViewController alloc] init];
// Add this line to move the close button on here!
[targetViewController.navigationItem setRightBarButtonItem:[self.navigationItem rightBarButtonItem]];
[self.navigationController pushViewController:targetViewController animated:YES];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment