I have an NSMutableArray
that stores values from JSON. I select a specific index from the array to display that value to the button.
That works fine and code that does this work is prepared inside the function.
When I call the function, for example, inside the button it works fine and returns the result I want. But if I call inside viewDidLoad
it returns:
** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds for empty array'
This is the code to display data to the button and my buttons are ten and my array has ten elements:
NSString *onemb =[[mobile firstObject]objectForKey:@"package"];
NSString *onedolar =[[mobile firstObject]objectForKey:@"rate"];
nus_dolar.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
nus_dolar.titleLabel.textAlignment = NSTextAlignmentCenter;
nus_dolar.titleLabel.numberOfLines = 2;
nus_dolar.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
[nus_dolar setTitle:[NSString stringWithFormat:@"%@\n%@", onedolar , onemb ] forState: UIControlStateNormal];
This is my calling function:
[self loadingHomePageData];