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

ArtOfWarfare

macrumors G3
Original poster
Nov 26, 2007
9,706
6,289
Here's the line of code:
Code:
UILabel *scoreLabelToAdd = [itemView viewWithTag:([[foundItemArray objectAtIndex:2] intValue] + 10)];

viewWithTag: returns a UIView. Assuming my code works properly, it should return, more specifically, a UILabel. I need to specify that it's a UILabel here, because otherwise later on when I ask for the text property it says that UIViews don't have a text property.

So, what suggestions are there for removing the warning? What's the best programming practice in a case like this? Make an all new subclass of UIView that returns a UILabel when it's asked for a labelWithTag: or something like that? (Seems silly given the existing class does nearly exactly what I want.)

Thanks for any help.
 
Here's the line of code:
Code:
UILabel *scoreLabelToAdd = [itemView viewWithTag:([[foundItemArray objectAtIndex:2] intValue] + 10)];

Simply recast it into the desired type:
Code:
UILabel *scoreLabelToAdd = [COLOR="Red"][B](UILabel *)[/B][/COLOR][itemView viewWithTag:([[foundItemArray objectAtIndex:2] intValue] + 10)];
 
Thanks!

I'd been doing it wrong; I had thought castes were done something like this:
Code:
(UILabel *)[scoreLabelToAdd.text intValue]

Silly me.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.