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

  • SEARCH
  • Home
  • 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 8396027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:26:27+00:00 2026-06-09T20:26:27+00:00

I am working in iPhone app with 5 screens. I want to refresh the

  • 0

I am working in iPhone app with 5 screens. I want to refresh the values in the screen 4th in UITabBarController. I have added @protocol in AppDelegate but it is not calling. This is the first time am using @protocol could you please help me to solve this issue,

In AppDelegate.h

@protocol ReloadViewControllerDelegate <NSObject>

-(void) refreshViewController:(NSString *)result;

@end

id refreshViewControllerDelegate;

@property (nonatomic, retain) id refreshViewControllerDelegate;

and i have synthesized.

In AppDelegare.m

@synthesize refreshViewControllerDelegate;

if ([refreshViewControllerDelegate conformsToProtocol:@protocol(ReloadViewControllerDelegate)]) 
{
   [refreshViewControllerDelegate performSelectorOnMainThread:@selector(refreshViewController:) withObject:@"YES" waitUntilDone:NO];                
}// Control not come inside of if Condition.... From here i want to update the fourthViewController..

But control not go inside of the if condition. Could you please guide me where am doing wrong?

In my 4th ViewController.h

#import "AppDelegate"

@interface fourthViewController : UIViewController <ReloadViewControllerDelegate>

In my 4th ViewController.m

-(void) refreshViewController:(NSString *)result
{
    NSLog(@"Result : %@", result);
}

Can anyone please help me to do this? Thanks in advance.

  • 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-06-09T20:26:29+00:00Added an answer on June 9, 2026 at 8:26 pm

    You are calling this code:

    if ([refreshViewControllerDelegate conformsToProtocol:@protocol(ReloadViewControllerDelegate)]) 
    

    But refreshViewControllerDelegate is this:

    id refreshViewControllerDelegate;
    

    conformsToProtocol checks to see if the object declares that it conforms to the protocol, which yours does not. If you want to specify conformity to a protocol you need to:

    id<ReloadViewControllerDelegate> refreshViewControllerDelegate;
    

    EDIT

    OK, on the performSelectorOnMainThread problem… That method is provided in a category for NSThread, and is not declared in the NSObject protocol. So, if you want to call that, then you need to declare your type as NSObject, which conforms to your protocol.

    NSObject<ReloadViewControllerDelegate> refreshViewControllerDelegate;
    

    EDIT

    OK, it looks like this is not a simple question about using a protocol, but a full tutorial. Since SO isn’t the place for such, I’ll try to give a brief one…

    A protocol is an interface declaration.

    @protocol ReloadChatViewControllerDelegate <NSObject>
    - (void)refreshViewController:(NSString *)result;
    @end
    

    That says there is a new protocol in town, with the name ReloadChatViewControllerDelegate and it also conforms to the NSObject protocol. Any class that adopts the new protocol must provide an implementation of refreshViewController. You can make a protocol method optional, by putting in an @optional section.

    @protocol ReloadChatViewControllerDelegate <NSObject>
    - (void)refreshViewController:(NSString *)result;
    @optional
    - (void)optRefresh;
    @end
    

    Now, let’s leave the adoption of the protocol for later. Say you are writing generic code, and you just want to know if the object you are given conforms to the protocol, and if so, invoke a method on it. Something like…

    @interface Bar : NSObject
    @property (nonatomic, weak) NSObject<ReloadChatViewControllerDelegate>  *refreshViewControllerDelegate;
    - (void)blarg;
    @end
    

    Now, the Bar class is providing a delegate property, so that it can be give some object that will help it do some work. However, that delegate object must at least be an NSObject, and conform to the ReloadChatViewControllerDelegate protocol.

    Now, ObjC (and C) is quite permissive, so you can force an object to be any type you want, but then you deserve the crash you get. Now, when blarg is called, the delegate is notified to do some work.

    Since the property type of the delegate already says it conforms to the given protocol, there is no need to check for conformity. We can just call the delegate method. Note that we must see if the object implements any optional protocol methods.

    @implementation Bar
    @synthesize refreshViewControllerDelegate = _refreshViewControllerDelegate;
    - (void)blarg {
        // Do something, then invoke the delegate
        [self.refreshViewControllerDelegate
            performSelectorOnMainThread:@selector(refreshViewController:)
                             withObject:@"YES"
                          waitUntilDone:NO];
        if ([self.refreshViewControllerDelegate respondsToSelector:@selector(optRefresh)]) {
            [self.refreshViewControllerDelegate optRefresh];
        }
    }
    @end
    

    However, if you want to be generic, and accept any object as a delegate (maybe you want to make it optional that the delegate conforms to some given protocol), then you can accept a plain id and then check to see it it conforms. In that case, you could declare your delegate as just an id (or some other type).

    @property (nonatomic, weak) id refreshViewControllerDelegate;
    

    Now, in your code, you need to check for conformity.

    - (void)blarg {
        // Do something, then invoke the delegate
        if ([self.refreshViewControllerDelegate
                conformsToProtocol:@protocol(ReloadChatViewControllerDelegate)]) {
            [self.refreshViewControllerDelegate
                performSelectorOnMainThread:@selector(refreshViewController:)
                                 withObject:@"YES" waitUntilDone:NO];
            if ([self.refreshViewControllerDelegate
                    respondsToSelector:@selector(optRefresh)]) {
                [self.refreshViewControllerDelegate optRefresh];
            }
        }
    }
    

    OK, now you have a protocol defined, and you have code that calls methods on the protocol. Two caveats.

    First, the delegate has to be set to an object. nil will respond false for any method, so it will of course not conform, nor do anything when sent any message.

    Second, you have to make sure that your delegate declares conformity to the protocol. Just implementing the methods is not conformity. If a class does not explicitly specify that is conforms to a protocol, then conformsToProtocol will return false, even if it implements the methods of the protocol.

    So, let’s specify some class that will act as our delegate by conforming to the protocol.

    @interface Foo : NSObject<ReloadChatViewControllerDelegate>
    - (void)refreshViewController:(NSString *)result;
    @end
    @implementation Foo
    - (void)refreshViewController:(NSString *)result {
        NSLog(@"Look, ma, I'm refreshed with %@", result);
    }
    @end
    

    It conforms to the protocol, provides an implementation for the mandatory method, and omits the optional one.

    Now, if you ran this code, you should see that marvelous code in all its splendor.

    Foo *foo = [[Foo alloc] init];
    Bar *bar = [[Bar alloc] init];
    bar.refreshViewControllerDelegate = foo;
    [bar blarg];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an iphone app and want to have a page showing multiple
Am working in an iPhone app using UITableView . I have added the editing
I am working on a message based iPhone app. I have a screen to
I am working on an iPhone app with Apple Push Notification integration. I have
I am working on an iPhone app, in which I have to enlist all
I am working on my first iPhone app and making good progress. But there
I am working on a side-scrolling iPhone app, and I have every resource, except
I have an existing iPhone app that was working fine in Xcode 4.0 prior
I have an iPhone app I am working on to make universal for iPhone
I am working in UITabBarController based iPhone app. My app having 5 taps .

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.