1

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 ?

Soumya Ranjan
  • 4,817
  • 2
  • 26
  • 51
user3115014
  • 667
  • 1
  • 8
  • 23

2 Answers2

1

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);

Francescu
  • 16,974
  • 6
  • 49
  • 60
0

Use NSObject's method superclass:

Class your_superclass = self.superclass;

Docs:

Returns the class object for the receiver’s superclass.

Avt
  • 16,927
  • 4
  • 52
  • 72