views:

41

answers:

0

Hi,

I wonder why this is not working?

UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
[self.view addSubview:infoButton];
[infoButton addTarget:self 
               action:@selector(showInfoViewController)     
     forControlEvents:UIControlEventTouchUpInside];
//NSLog(@"%@", [infoButton description]); //button seems to be well created 
UIBarButtonItem *infoBarItem = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
[infoBarItem setWidth:infoButton.bounds.size.width];
//NSLog(@"%@", [infoBarItem description]); //infoBarItem also seem to be ok?

NSMutableArray *items = [[toolbar items] mutableCopy];
//NSLog(@"items: %@", [items description]); //before change
[items replaceObjectAtIndex:0 withObject:infoBarItem];
//NSLog(@"inserted");
//NSLog(@"items: %@", [items description]); //after change, the object was indeed replaced
[toolbar setItems:items];
//nothing happens

I want to change a normal bordered "Info" item created in IB with a UIButton: UIButtonTypeInfoLight but changes seems to have no effect. I still have my normal bordered "info" button without errors or a clue of what is happening here.

How do I do this?

Thanks in advance.

UPDATE: 2010/10/06

First, I am using the split view template for iPad applications and I want to change the button of the top bar in the detail viewcontroller (The right big one). I have realized that there is a hidden button, which is the one that appears and disappears when changing device orientation. Is strange because this button is supposed to be added/removed when rotating but even I don't rotate the device is there is just its width is 0. (I set my view controller not to support rotations) I know because I printed the barbuttonitems and its selectors and there it was! So What I was changing was that button and since its width is 0 I didn't show.

When trying my app in 4.2beta the button appeared! and it became clearer.

I wonder if anyone experiencing the same problem here? Create a Splitview template for 3.2 and try it in 4.2. What is happening here?