Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

RossOliver

macrumors regular
Original poster
Nov 6, 2006
157
0
Hey,

I have a UIViewController that puts a '+' button on its UINavigationBar:

Code:
-( void )addItem
{
	[self presentModalViewController:[[UINavigationController alloc] initWithRootViewController:[[AddItemModalViewController alloc] init]] animated:YES];
}

-( void )loadView
{
	// Set up navigation buttons.
	UIButton *addButton = [[UIButton buttonWithType:UIButtonTypeNavigation] retain];
	[addButton setImage:[UIImage imageNamed:@"plus.png"] forStates:( UIControlStateNormal & UIControlStateHighlighted )];
	[addButton addTarget:self action:@selector( addItem ) forControlEvents:UIControlEventTouchUpInside];
	self.navigationItem.customRightView = addButton;
	[addButton release];
	
	// Create a custom view hierarchy.
	UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
	view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
	self.view = view;
	[view release];
}

When the '+' button is hit, the modal view controller is loaded. The controller has a button to cancel, which dismisses the modal view controller and returns to the previous UIViewController:

Code:
-( void )cancel
{
	[self dismissModalViewControllerAnimated:YES];
}

-( void )loadView
{	
	// Add button to cancel.
	UIButton *cancelButton = [[UIButton buttonWithType:UIButtonTypeNavigationBack] retain];
	[cancelButton setTitle:@"Cancel" forStates:( UIControlStateNormal & UIControlStateHighlighted )];
	[cancelButton addTarget:self action:@selector( cancel ) forControlEvents:UIControlEventTouchUpInside];
	self.navigationItem.customLeftView = cancelButton;
	[cancelButton release];

	// Construct the table view for adding an item.
	tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStyleGrouped];
	tableView.delegate = self;
	tableView.dataSource = self;

	// Set as main view.
	self.view = tableView;
}

The problem I am having is that once the modal view controller is called and dismissed, calling it again by hitting the '+' button works, but the button itself doesn't do the little animation of being pushed down...

Not the end of the world but it is driving me mad - has anyone else experienced this? From what I can see I've done everything correctly by the sample code in apples demo programs, but they seem to work so I guess I went wrong somewhere :-/

Thanks for your time,

-Ross
 
I know this was ages ago but did you figure out what the problem was? I am having a similar issue! Thanks
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.