Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6605503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:17:29+00:00 2026-05-25T19:17:29+00:00

For whatever reason, the following code isn’t working: #import <Foundation/Foundation.h> @interface UIView (FindUIViewControllerParent) –

  • 0

For whatever reason, the following code isn’t working:

#import <Foundation/Foundation.h>

@interface UIView (FindUIViewControllerParent)

- (UIViewController *) firstAvailableUIViewController;
- (id) traverseResponderChainForUIViewController;

@end


#import "UIView+FindUIViewControllerParent.h"

@implementation UIView (FindUIViewControllerParent)

- (UIViewController *) firstAvailableUIViewController 
{
    return (UIViewController *)[self traverseResponderChainForUIViewController];
}

- (id) traverseResponderChainForUIViewController 
{
    id nextResponder = [self nextResponder];
    if ([nextResponder isKindOfClass:[UIViewController class]]) 
    {
        return nextResponder;
    } 
    else if ([nextResponder isKindOfClass:[UIView class]]) 
    {
        return [nextResponder traverseResponderChainForUIViewController];
    } 
    else 
    {
        return nil;
    }
}

@end

parentViewController = [self firstAvailableUIViewController];

The firstResponder is coming back as nil, instead of being the parent view controller (when I did it without the category it worked out fine). I’ve read some other threads that say to make some adjustments to Other Linking Options in project settings, and I’ve tried these and it still doesn’t work. Can anyone see what I’m doing wrong here? (this code is copied nearly exactly from another thread that got a ton of up votes).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:17:30+00:00Added an answer on May 25, 2026 at 7:17 pm

    I found my problem. I was looking for and storing the nextResponder in the init method my view, before the view had even been attached to a view controller. That’s why it was correctly showing up null. I used my category method in the button action method instead and then it worked fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On whatever reason this is not working (says 'file not found'), set in=c:\myprogram\_save cd
I'm working on a legacy app and for whatever reason it's trying to stuff
In the following code, whatever is passed as retval is evaluated as given for
I'm sure I'm overlooking the obvious as I've got countless working buttons...but...for whatever reason
For whatever reason, our company has a coding guideline that states: Each class shall
For whatever reason, I have a lot of clients that have existing data that's
For whatever reason, ThreadPool 's QueueWorkItem doesn't return an IAsyncResult or some other handle
For whatever reason, std::cout does not display anything with my application. The description of
Assuming you can't use LINQ for whatever reason, is it a better practice to
I've got a stylesheet that will not, for whatever reason, apply list-style-type to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.