0

I'm having trouble making sense of the following:

UILabel *label = (UILabel *)[cell viewWithTag:1000]; 

I understand that UILabel is a class. So we're creating a pointer named *label that points to an instance of UILabel.

Right of the equals sign, I understand that [cell viewWithTag:1000]; is passing cell a method named viewWithTag with the argument 1000.

What does the (UILabel *) before that mean?

2
  • It isn't passing a method; it's sending a message. Passing a method is a different and quite specific idea. Commented Feb 7, 2012 at 21:46
  • Sorry, coming from other OO languages and still getting my head around the terminology. Commented Feb 7, 2012 at 21:54

2 Answers 2

2

It means to cast the object type to a UILabel*. By default, viewWithTag: returns a UIView*

Sign up to request clarification or add additional context in comments.

Comments

1

It is casting the result to a UILabel. The syntax is the same as in C - (Objective-C is a super-set of C).

You can also check the type before using it (although not really necessary if you are confident of what is being returned) using isKindOfClass

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.