Reputation: 697
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
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