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 9260117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:48:53+00:00 2026-06-18T12:48:53+00:00

I create new tabbed view project in xcode, in appdelegate I created a protocol

  • 0

I create new tabbed view project in xcode, in appdelegate I created a protocol

.h file

@protocol myProtocol <NSObject>
-(void)myProtocolMethodOne;
@end
.
.
.
@property (weak) id<myProtocol> mypDelegate;

.m file

@synthesize mypDelegate;
.
.
.
//Inside didFinishLaunchingWithOptions
[mypDelegate myProtocolMethodOne];

In firstViewController & secondViewController (both are displayed as two different tab) I did this in both

AppDelegate *ad = (AppDelegate*)[[UIApplication sharedApplication]delegate];
    [ad setMypDelegate:self];
.
.
.
-(void)myProtocolMethodOne
{
    NSLog(@"1st VC");
    [[self tabBarItem]setBadgeValue:@"ok"];
}

The code is working perfectly but only secondViewController is responding.

I am looking for a broadcasting and listener kind of mechanism using delegates not notifications.

I searched a lot but did find any solutions except this but code is advance for me to understand, so I am taking a step by step approach to understand this by starting form a simple project. Please help me regarding this. How both viewcontrollers can respond to delegate at same time, what should I do?

  • 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-18T12:48:54+00:00Added an answer on June 18, 2026 at 12:48 pm

    In your case is enough to hold an array with all delegates, by holding an array of delegates, possibly as a private property, and allowing to add/remove delegates:

    @interface AppDelegate() // .h file
    
    @property (nonatomic,strong,readwrite) NSMutableArray* delegates;
    
    @end 
    
    // .m file
    
    - (void) addDelegate: (id<MyProtocol>) delegate // By convention the first letter should be capital.
    {
        // Optional code you may need to execute before adding it.
        [delegates addObject: delegate];
    }
    

    I leave to you the removeDelegate method, it’s very simple to implement.

    How to call the delegates methods

    It’s enough to call the selector on every object:

    [delegates makeObjectsPerformSelector: myProtocolMethodOne];
    

    If you need to take return values it’s better to do it this way:

    NSMutableArray* returnValues= [NSMutableArray new];
    for(id<MyProtocol> delegate in delegates)
    {
        id result= [delegate myProtocolMethodTwo]; // Method returning a value
        [returnValues addObject: result];
    } 
    

    How to add the delegates

    In every controller (up to N times) you should be able to add it:

    AppDelegate *ad = (AppDelegate*)[[UIApplication sharedApplication]delegate];
    [ad addDelegate:self];
    

    Additional problem: You may want to have weak delegates, but a NSArray holds strong references. Here you can find a nice solution for this:

    NSArray of weak references (__unsafe_unretained) to objects under ARC

    It basically says to use NSValue to store weak reference using the valueWithNonretainedObject method.

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

Sidebar

Related Questions

I created a new tabbed view project in Xcode in firstViewController I created a
I just created a new iPhone tabbed Application using xcode project template, without storyboard.
I started a new IOS app project in Xcode 4.3.1. I selected tabbed application
It's been some time since I created a new project in Xcode. Today I
I need a tabbed application with core data persistence. when i create a new
Im trying to create new file on D: drive with c/c++ I found this
I can't create New Project on my Visual Web Developer 2008 Express with SP1.
I just created a new activity from eclipse new Android-file wizard. I created the
I am new to Javascript I want to create tabbed menu bar in that
When I create a new Tabbed Application for a universal app, 5.0 and higher

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.