4

I am trying to change the color properties of a UIPageControl object from code. However it crashes. Settning the properties from Interface Builder works just fine.

The code:

float x = isLight ? 0.8f : 0.2f;
UIColor markedColor = UIColor.FromRGB (x, x, x);
pageControll.CurrentPageIndicatorTintColor = markedColor;
pageControll.PageIndicatorTintColor = isLight ? UIColor.White : UIColor.Black;

The error I get (on the third row):

Objective-C exception thrown. Name: NSRangeException Reason: *** -[__NSArrayM objectAtIndex:]: index 4294967295 beyond bounds for empty array

Any ideas?

Stephane Delcroix
  • 16,134
  • 5
  • 57
  • 85
Sunkas
  • 9,542
  • 6
  • 62
  • 102

1 Answers1

10

Found the problem. Seems to be a bug in the SDK.

Since I had not yet received the data to "populate" the UIPageControl, the property Pages was set to 0. Changing this to 1 solved it.

float x = isLight ? 0.8f : 0.2f;
UIColor markedColor = UIColor.FromRGB (x, x, x);
if (pageControll.Pages < 1) {
    pageControll.Pages = 1;
}
pageControll.CurrentPageIndicatorTintColor = markedColor;
pageControll.PageIndicatorTintColor = isLight ? UIColor.White : UIColor.Black;
Sunkas
  • 9,542
  • 6
  • 62
  • 102