Domanda

I have a UIToolbar that has two buttons, two flexible margins and a segment control within it. I have it set up so that when the user selects the refresh button, the button is hidden, a activity indicator takes its place, and once the operation is done, the button is put back and the activity indicator is stopped. The only way to hide UIBarButtonItems is to remove the from the toolbar array and then re-add them when needed. That is all fine and dandy. My question is, when I re-add the object, how do I specify it's place in the array. Right now it adds the object to the end of the array, there for the button is on the far right. I would like it to be on the left side. My code is below. Thanks.

toolbarItems = [mapToolbar.items mutableCopy];
[toolbarItems removeObject:refreshButton];
mapToolbar.items = toolbarItems;

spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
spinner.center = CGPointMake(298, 22);
[mapToolbar addSubview:spinner];
[spinner startAnimating];

do operation....

[toolbarItems addObject:refreshButton];
mapToolbar.items = toolbarItems;

[spinner stopAnimating];
È stato utile?

Soluzione

Since you are copying toolbar items to array, you might use [toolbarItems insertObject:refreshButton atIndex:0] instead of addObject.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top