Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the ViewController's name

I have an app that is a TabBarControllers with 4 tabs. Now, in didFinishLaunchingWithOptions I did this:

    UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
    lpgr.minimumPressDuration = 5.0;
    lpgr.delegate = self;
    [self.window addGestureRecognizer:lpgr];
    [lpgr release];

This part is working and the long press gesture is recognize in all the four tabs. Now, I want to pass the name of the current ViewController that the user is currently pressing on so I can pass it in my function that handles the long press event.

like image 407
Diffy Avatar asked Oct 16 '25 15:10

Diffy


2 Answers

You can try:

NSStringFromClass([YourViewController class]);

and for current view controller, use:

NSStringFromClass([self class]);
like image 100
Kjuly Avatar answered Oct 19 '25 04:10

Kjuly


Try Below One(Updated)

AS you Told you have added Four ViewController on TabBar Controller.

Get The ViewController from TabBarController As:

UIViewController *current = tabBarController.selectedViewController;

NSArray *controllerNameArray = [current childViewControllers]; 

NSLog(@"className %@",[controllerNameArray objectAtIndex:0]);

 

I Hope It really Helpful to you...!!!

like image 41
Kamar Shad Avatar answered Oct 19 '25 04:10

Kamar Shad