UIActivityIndicatorView in UITableView section header disappears on orientation change
I have an iPhone app containing a UITableView in grouped style. In the ViewController I defined an UIActivityIndicatorView as a property:
self.browsingIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
browsingIndicator.hidesWhenStopped = YES;
I want to place this spinner in one of the tables section headers:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSIn开发者_StackOverflowteger)section {
UIView *sectionHeader = [[[UIView alloc] init] autorelease];
[sectionHeader addSubview:browsingIndicator];
browsingIndicator.center = CGPointMake(20, 30);
return sectionHeader;
}
This is working. Now the problem: Once I change the device orientation the activity indicator vanishes, it only reappears when I drag it out of the visible screen and back in. Turning the device back to the original orientation doesn't help, changing "hidesWhenStopped" to NO neither.
Can someone point me in the right direction? Thanks!
Thanks for your answer Mike, but I don't think that's it. The UIActivityIndicatorView is positioned and resized correctly but it is not drawn. When I force the sectionHeader to redraw (by scrolling it out of view) it spins at exactly the right place, even in landscape orientation.
I tried to explicitly set the autoResizingMask, but that didn't change the1 disappearing.
Edit: Couldn't comment on your answer, I didn't really get the post/comment without registering thing here, sorry :-/
Edit2:
[sectionHeader addSubview:browsingIndicator];
seems to be part of the problem. If I return browsingIndicator directly it is working.
Kind of solved now: If I define the UIView for the section header outside of the viewForHeaderInSection method and then just return it, it works.
You want to set the autoResizingMask property of the spinner appropriately.
精彩评论