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
?
Asked
Active
Viewed 1,279 times
1

Soumya Ranjan
- 4,817
- 2
- 26
- 51

user3115014
- 667
- 1
- 8
- 23
-
How about `[myElement superclass]`... (or `isKindOfClass:` passing the super class that you want to test against) – Alladinian May 12 '14 at 09:15
-
are u subclassed the UI elements ... ? – Shankar BS May 12 '14 at 09:18
2 Answers
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