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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:18:57+00:00 2026-06-08T04:18:57+00:00

Goal: I want to use the Observer Pattern so that when one uiimageview receives

  • 0

Goal:

I want to use the Observer Pattern so that when one uiimageview receives a different background image, then 2 other uiimageviews will listen for that change, and then change themselves.

Strategy:

Based on what I read about observer pattern in objective-c, I decided to implement the nsnotificationcenter.

Code:

self refers to the RemoteViewManagerController, updateButtons is the method that will be called when the ImageSwap event is fired, and object refers to the “main” uiimageview, that is, the uiimageview that when changed will cause changes in other uiimageviews.

- (void)registerButtonObserver:(UIView *)currentView
{  
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateButtons:) name:@"ImageSwap" object:[self.view viewWithTag:1]];
}

setDefaultButtons is invoked, and we iterate through the buttons and target buttons based on tag. The “main” uiviewimage has a tag of 1. So we call setImageChange to change the background image of that button, and as a result, I want to fire the ImageSwap event, to change the other two uiimageview buttons, and I pass in those buttons part of the userinfo dictionary. The idea is when updateButtons is invoked, I can reference those buttons in the userinfo dictionary.

- (void)setDefaultButtons:(UIView *)currentView
{
    for( UIView *view in currentView.subviews ) {  
        if( [view isKindOfClass:[UIButton class]] ) {  
            if( view.tag == 1 ){                
                [self setImageChange:@"fence" forButton:view];

                NSArray *keys = [NSArray arrayWithObjects:@"subview1", @"subview2", nil];
                NSArray *objects = [NSArray arrayWithObjects:[self.view viewWithTag:4], [self.view viewWithTag:5], nil];
                NSDictionary *items = [NSDictionary dictionaryWithObjects:objects 
                                                                       forKeys:keys];
                NSLog(@"But we sure to get here right");
                [[NSNotificationCenter defaultCenter]postNotificationName:@"ImageSwap" object:view userInfo:items];                
            }
            else if(view.tag == 2){
                [self setImageChange:@"siren" forButton:view];
            }
            else if(view.tag == 3){
                [self setImageChange:@"auxiliary" forButton:view];
            }
        }  
    }
}

Note that I know that we get to the postNotificationName line, because this line does fire: NSLog(@”But we sure to get here right”);

I don’t get any errors. But this line in RemoteViewManagerController.m:

- (void)updateButtons:(NSNotification*)notification 
{
    NSLog(@"Do we get here?");
}

is never called.

  • 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-08T04:19:01+00:00Added an answer on June 8, 2026 at 4:19 am

    I believe that when two subviews have the same tag, -viewWithTag: just returns the first one that it finds. So if there happen to be two views with tag=1, it’s quite possible that you’re observing the wrong one. Try changing the object parameter in you -addObserver... call to nil, which will indicate that you want to observe that notification for all objects.

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

Sidebar

Related Questions

I want to extract kernel symbols from a u-boot image The final goal is
I have the pages that I want to set as a goal in Google
Here's my list that I want to expand/collapse: My goal is simply to toggle
Goal: I want to use jsf`s i18n Scenario: creating resource bundle (utf-8) file info:
Which API should I use? Which one is more promising? My main goal is
I want to use templated ComboBoxItems which consist of an Image and a Label.
Goal: I want to get the text from the selected element and then create
I want to use Shindig as an OpenSocial container. In order to do that
I want to use 1 port for both unencrypted TCP and SSL. The goal
Note: I do NOT want to use any framework. The goal is just to

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.