Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

marius4143

macrumors newbie
Original poster
Jul 23, 2008
3
0
Does anyone have an example of the proper way to use the resuingView parameter when implementing pickerView:viewForRow:forComponent:reusingView: in a UIPickerViewDelegate?

The documentation states that reusingView is "A view object that was previously used for this row, but is now hidden and cached by the picker view."

and: "If the previously used view (the view parameter) is adequate, return that. If you return a different view, the previously used view is released. The picker view centers the returned view in the rectangle for row."

I need to create UILabel views so I can right justify things, and I have that working by always returning my copy of the view, but it seems like things could be made more efficient by returning the view passed to me if it's "adequate". So, how do I tell if the view is adequate?

I've tried something like this:


Code:
// check to see if the view we're given is a UILabel and return that view 
if ([view isMemberOfClass:[UILabel class]])
{
  v = (UILabel *)view;
  return v;
}
else
{
  ... return  a UILabel instance for this row ...
}


But the view I'm being passed is never a UILabel instance. That or I'm not using isMemberOfClass correctly.

Thoughts anyone?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.