Reputation: 395
I have a UIScrollView
(self.scroller
in code) and i want to set its size based on the amount of objects in an array, but i get an error when the view appears. error :
Terminating app due to uncaught exception: 'NSInvalidArgumentException', reason: '-[__NSCFString setFrame:]: unrecognized selector sent to instance 0x8076080'
Here is the code in question :
for (int i = 0; i < [scoresArray count]; i++)
{
UILabel *scoreLabel = [scoresArray objectAtIndex:i];
CGRect labelPos = CGRectMake(10, i * 50, 300, 50);
[scoreLabel setFrame:labelPos];
[self.scroller setFrame:CGRectMake(0, 90, 320, ([scoresArray count] * 50))];
[self.scroller addSubview:scoreLabel];
}
Am i doing something wrong?, how can i fix it? (I only want to se the height) if that helps.
Upvotes: 0
Views: 62
Reputation: 26682
There's a couple of problems here. First is that an error has occurred with your memory, so self.scroller
no longer represents the address of a UIScrollView
instance. Some other class of object is at 0x8076080
, and it's not a UIScrollView
.
Most likely, it's a string, and that hint comes from the exception detail above.
This problem can occur from a number of reasons. First, you need to debug that issue by reviewing how you handle memory management. Possibly you have the self.scroller
as a weak reference and the runtime has already deallocated that object.
Next, I think you are incorrectly setting the UIScrollView
size. Understand that a UIScrollView
has two sizes. First, the size of it's view. That is the "view port" that you see within the app. Secondly, there's the size of the content itself. For a scroll view to scroll, there has to be more content than is visible within the view port. Otherwise there'd be nothing to scroll, right?
So, my guess is you want to be setting self.scroller.contentSize
rather than the frame of the view itself.
Upvotes: 1