user3115014
user3115014

Reputation: 697

Get parent class name from custom UI elements in iOS

I have some custom UIElements like UILabel , UITextFields etc in my iOS App . Now i want to get the original element name from which they are derived from on each touch event . How to get the parent class name from the custom UIElements ?

Upvotes: 1

Views: 1326

Answers (2)

Francescu
Francescu

Reputation: 17054

You can use NSObject superclass method to get the superclass.

But in your case you don't want to care about how many inheritances there are.

So the best is to use isKindOfClass.

if ([element isKindOfClass:[UILabel class]])
{
    //Do your stuff here
}

In order to complete your exact question, to retrieve the parent class name:

NSString *parentClassName = NSStringFromClass(element.superclass);

Upvotes: 1

Avt
Avt

Reputation: 17053

Use NSObject's method superclass:

Class your_superclass = self.superclass;

Docs:

Returns the class object for the receiver’s superclass.

Upvotes: 0

Related Questions