I have a UIView
that contains more than 20 UIButtons
. On clicking each of these buttons, i reveal a distinct UIView
containing UIPickerView
and two UIButtons
('OK','CANCEL') as its subviews(each button corresponds to revealing separate and distinct UIVIews
).
I have created all the UIViews
(20 of them) through IB and set all of them to be hidden initially. So whenever i click a button, it reveals a view and on clicking 'OK' or 'CANCEL' hides the view again.
The problem is when this View Controller is pushed from another, it takes a long time to load(like 5 seconds) and i'm suspecting the time lag is due to loading all the subviews before the parent UIView
appears.
I want to reduce or nullify this time lag.
EDIT:
I have trimmed code in viewDidLoad
.
- (void)viewDidLoad
{
@try
{
[super viewDidLoad];
NavigationBarButtonItems *nav=[[NavigationBarButtonItems alloc]init];
self.navigationItem.rightBarButtonItems = [nav BarButtonItems];
//the following properties are only for 'quantity' button and its view whereas the original method contains same properties set for all 20 buttons and its views.
_quantityView.layer.cornerRadius=8;
_quantityView.clipsToBounds=YES;
_quantityButton.layer.cornerRadius=8;
_quantityView.hidden=YES;
//DEFAULT SELECTED VALUES
selectedQuantity=@"";
//only quantity array is initialised here to populate its pickerview. The actual code contains more than 20 arrays initalised for each picker view
NSArray *quantityData=[[NSArray alloc]init];
for(int i=1;i<=100;i++) [quantityData addObject:[NSString stringWithFormat:@"%d",i]];
quantityArray=quantityData;
// Do any additional setup after loading the view.
}
@catch (NSException *exception)
{
NSLog(@"Medications-> View did Load-> %@",exception.name);
}
}
This is one such UIButton
('QUANTITY') and the UIView
('QUANTITYVIEW') to be shown when clicked:
- (IBAction)OnClickQuantityButton:(id)sender
{
@try
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[_mainView setNeedsDisplay];
CGPoint centerPoint = CGPointMake(160, _mainScrollView.contentOffset.y+228);
_quantityView.center= centerPoint;
_quantityView.hidden=NO;
});
}
@catch (NSException *exception)
{
NSLog(@"Medications-> quantity button-> %@",exception.name);
}
}
- (IBAction)OnClickQuantityOkButton:(id)sender
{
@try
{
_quantityLabel.text=selectedQuantity;
_quantityView.hidden=YES;
}
@catch (NSException *exception)
{
NSLog(@"Medications-> quantity ok button-> %@",exception.name);
}
}
- (IBAction)OnClickQuantityCancelButton:(id)sender
{
_quantityView.hidden=YES;
}