简体   繁体   中英

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:(NSInteger)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.

您想要适当地设置微调器的autoResizingMask属性。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM