Re: Accessing items in a UIScrollView?
Re: Accessing items in a UIScrollView?
- Subject: Re: Accessing items in a UIScrollView?
- From: Fritz Anderson <email@hidden>
- Date: Fri, 30 Jul 2010 14:30:40 -0500
On 30 Jul 2010, at 2:14 PM, Eric E. Dolecki wrote:
> -(void) buttonClicked:(id)sender
> {
> int tag = [sender tag];
>
> for(int i=0;i<20;i++){
> BasicListItem *tmp = (BasicListItem*)[scrollView viewWithTag:i];
>
> if( tag != i ){
> [tmp setState:NO]; //Barf here
> }
> }
> NSLog(@"%d",tag);
> }
>
>
> *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
> reason: '-[UIScrollView setState:]: unrecognized selector sent to instance
> 0x593e820'
>
>
> How can I dig into the scrollview and access those BasicListItem objects?
1. Use the blasted NSArray. It's a data structure that accesses a group of objects in order, by a numeric index, and can be efficiently iterated. That's what you want.
-(void) buttonClicked: (id) sender
{
for (BasicListItem * item in self.listItemArray)
item.state = (item == sender);
}
2. This is what the documentation says -[UIView viewWithTag:] returns:
> The view in the receiver’s hierarchy that matches tag. The receiver is included in the search.
I assume you left the scroll view's tag at zero? The exception label is the clue: It says you sent setState: to the scroll view.
— F
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden