mercredi 24 juin 2015

Get superView of custom class

I have a custom class myCustomClass which is a subclass of UITextField. (I'm going to call myCustomClass in a viewControllers class.)

In myCustomClass, I'm trying to check what kind of viewController the class that called it is. (UIViewController, UITableViewController etc.)

I tried:

if ([self.superview.nextResponder isKindOfClass[UIViewController class]]) {
    NSLog(@"View Controller");
} else if ([self.superview.nextResponder isKindOfClass[UITableViewController class]) {
    NSLog(@"TableView Controller");
}

I only get a result if the superclass is a viewController. So I did the following:

NSLog(@"%@", self.superview.nextResponder);

Results

UIViewController Class - ViewController

UITableViewController Class - UITableViewCell

How can I check if it's a UITableViewController?

See more ..

Aucun commentaire:

Enregistrer un commentaire