Alex
Alex

Reputation: 141

Compiler warnings about methods not found or not declared

I have started using (ARC) with iOS 5, but I have a problem which appears often.

First case:

[[cell viewWithTag:999] setTextColor:[UIColor blackColor]];

this line causes the problem:

Receiver type 'UIView' for instance message does not declare a method with selector 'setTextColor:'.

Second case:

[delegate setForTheFirstTime:TRUE];

this line cause the problem:

No known instance method for selector 'setForTheFirstTime:'.

I have a lot of problems like these when I use a delegate.

To fix these two problems, must I use a method like performSelector:?

Upvotes: 0

Views: 445

Answers (2)

Yann
Yann

Reputation: 128

viewWithTag method is returning an UIView object. So when you call the setTextColor method, the receiver is a UIView and there is no setTextColor method for a UIView. You have to cast your object to the correct class. Here you want a UILabel.

Upvotes: 0

Firoze Lafeer
Firoze Lafeer

Reputation: 17143

You just need to declare 'delegate' as the correct type, which will require you to import that type's header. The compiler needs to know that your delegate object understands 'setForTheFirstTime:' and the compiler needs the declaration for that method.

In the first case with viewWithTag:, you need to cast the result to the correct class so the compiler can know about that 'setTextColor:' method.

Assuming this view is a UILabel:

[(UILabel*)[cell viewWithTag:999] setTextColor:[UIColor blackColor]];

Upvotes: 2

Related Questions