The text is offset wrong by the first launch of UIRefreshControl... later sometimes the refresh text doesn't show up at all and just the spiny is visible
I don't think i had this issue with iOS6... might be related to iOS7
Is in a UITableViewController added as a child to a VC, which resides in a modal presented UINavigationController
- (void)viewDidLoad {
[super viewDidLoad];
[self setRefreshControlText:@"Getting registration data"];
[self.refreshControl beginRefreshing];
}
- (void)setRefreshControlText:(NSString *)text {
UIFont * font = [UIFont fontWithName:@"Helvetica-Light" size:10.0];
NSDictionary *attributes = @{NSFontAttributeName:font, NSForegroundColorAttributeName : [UIColor blackColor]};
self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:text attributes:attributes];
}
The solution for me was to set a text in
viewDidAppear
, no need to callbeginRefreshing
orendRefreshing
on the mainQueueI had the same problem and for me it worked with
layoutIfNeeded
after setting the attributedTitle:Cédric suggested to use
[self.refreshControl setNeedsLayout]
, but this does not force an immediate update of the view, so you must uselayoutIfNeeded
.I had the same problem, I did solve it by setting attributed text with space string to refresh control directly after init refresh control
After that, setting new attributed text to refresh control was without any problems.
UPDATE
I noticed that problem come back when I use attrsDictionary:
this code works fine
and this make refreshControl's title appear directly after view loaded
I didn't find solution yet.
UPDATE
Finally found solution, after refreshcontrol init set attributed string also with attributes:attrsDictionary
so after that there is no problem to set new refreshcontrol's title.
I finally found the holy grail on this, which looks working in all cases
note :
UIRefreshControl
is added to aUITableViewController
(note, never addUIRefreshControl
just as subview to a normal UIVIewController'sUITableView
) (best to addUITableViewController
as a child VC inside aUIViewController
if you must)note : that this also fixes the problem, that the UIRefreshControl is not vissible at first refresh (link)
Add to you .h
Add to you .m
Use only methods
calling
endRefreshing
underviewWillAppear
did it for me:Under iOS7 with a custom
UITableViewController
inside aUINavigationController
This is definitely an iOS 7 bug, but I haven't figured out exactly what caused it. It appears to have something to do with the view hierarchy — adding my UITableViewController as a child view to a wrapper view controller appeared to fix it for me at first, although the bug is back since iOS 7 GM.
It looks like adding the following code to your UITableViewController after creating the refresh view fixes the positioning issue for good: