I am writing a program that employs a UIProgressView that gets added programmatically and hidden/revealed during program execution. I have the following code that worked in iOS 5. The code adds the UIProgressView "below" a UITableView by adding the UIProgressView as a subview of the superview of the UITableView. This also keeps the UIProgressView in one place while the UITableView scrolls.
In viewDidLoad, I set the frame of the UIProgressView
UIProgressView * progressBar = [[[UIProgressView alloc]
initWithProgressViewStyle:UIProgressViewStyleBar] retain];
progressBar.hidden = NO;
progressBar.progress = [[NSUserDefaults standardUserDefaults] floatForKey:@"progress"];
//Set up the UIProgressView
frameForProgressBar = CGRectMake(0.0f,
self.tableView.frame.origin.y +
self.tableView.frame.size.height -
progressBar.frame.size.height,
self.tableView.frame.size.width,
progressBar.frame.size.height);
progressBar.frame = frameForProgressBar;
insetsForTableView = UIEdgeInsetsMake(0.0, progressBar.frame.size.height, 0.0, 0.0);
and then when I want the UIProgressView to appear
// Add the Progress bar to the Window
progressBarState = ADD_PROGRESS_BAR;
[self.view.superview addSubview:progressBar];
and so that I can see the UIProgressView, I change the contentInsets of the UITableView. To accommodate iOS 7, I read that changes to contentInsets must happen in viewWillLayoutSubviews.
-(void) viewWillLayoutSubviews
{
switch (progressBarState)
{
case ADD_PROGRESS_BAR:
// Set the frame of the UITableView to allow the UIProgressView to appear
self.tableView.contentInset = insetsForTableView;
break;
case REMOVE_PROGRESS_BAR:
self.tableView.contentInset = UIEdgeInsetsZero;
break;
default:
break;
}
progressBarState = UNDEFINED_PROGRESS_BAR;
}
I run this code through the debugger and viewWillLayoutSubviews does get called. However, I don't see the UITableView resize and I don't see the UIProgressView. I tried setting a frame for the UITableView to make it much smaller than the screen and then setting a frame for the UIProgressView that would have placed it in the "empty" space. But, I was still unable to see the UIProgressView.
Can someone suggest why I can't see the UIProgressView?
Thanks,
Jason Mazzotta
Set automaticallyAdjustsScrollViewInsets property of UIViewController to NO. Since this property is available for iOS 7 and later so check availability using respondToSelector method.
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.