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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:00:52+00:00 2026-06-13T20:00:52+00:00

I am writing an app which is a sort of dictionary – it presents

  • 0

I am writing an app which is a sort of dictionary – it presents the user with a list of terms, and when clicked on, pops up a dialog box containing the definition. The definition itself may also contain terms, which in turn the user can click on to launch another definition popup.

My main app is stored in ‘myViewController.m’. It calls a custom UIView class, ‘CustomUIView.m’ to display the definition (this is the dialog box that pops up). This all works fine.

The text links from the CustomUIView then should be able to launch more definitions. When text is tapped in my CustomUIView, it launches another CustomUIView. The problem is, that this new CustomUIView doesn’t have access to the hash map which contains all my dictionary’s terms and definitions; this is only available to my main app, ‘myViewController.m’.

Somehow, I need to make my hash map, dictionaryHashMap, visible to every instance of the CustomUIView class. dictionaryHashMap is created in myViewController.m when the app opens and doesn’t change thereafter.

I don’t wish to limit the number of CustomUIViews that can be opened at the same time (I have my reasons for doing this!), so it would be a little resource intensive to send a copy of the dictionaryHashMap to every instance of the CustomUIView. Presumably, the solution is to make dictionaryHashMap a global variable.

Some of my code:

From myViewController.m:

- (void)viewDidLoad
{
    self.dictionaryHashMap = [[NSMutableDictionary alloc] init]; // initialise the dictionary hash map
    //... {Code to populate dictionaryHashMap}
}

// Method to pop up a definition dialog
- (void)displayDefinition:(NSString *) term
{
    NSArray* definition = [self.dictionaryHashMap objectForKey:term]; // get the definition that corresponds to the term
    CustomUIView* definitionPopup = [[[CustomUIView alloc] init] autorelease]; // initialise a custom popup
    [definitionPopup setTitle: term];
    [definitionPopup setMessage: definition];
    [definitionPopup show];
}

// Delegation for sending URL presses in CustomUIView to popupDefinition
#pragma mark - CustomUIViewDelegate
+ (void)termTextClickedOn:(CustomUIView *)customView didSelectTerm:(NSString *)term
{
        myViewController *t = [[myViewController alloc] init]; // TODO: This instance has no idea what the NSDictionary is
        [t displayDefinition:term];
}

From CustomUIView.m:

// Intercept clicks on links in UIWebView object
- (BOOL)webView: (UIWebView*)webView shouldStartLoadWithRequest: (NSURLRequest*)request navigationType: (UIWebViewNavigationType)navigationType {
    if ( navigationType == UIWebViewNavigationTypeLinkClicked ) {
        [myViewController termTextClickedOn:self didSelectTerm:request];
        return NO;
    } 
    return YES;
}

Any tips on how to make the dictionaryHashMap visible to CustomUIView would be much appreciated.

I have tried making the dictionaryHashMap global by doing the following:

  • Changing all instances of ‘self.dictionaryHashMap’ to ‘dictionaryHashMap’
  • Adding the line ‘extern NSMutableDictionary *dictionaryHashMap;’ to CustomUIView.h
  • Adding the following outside of my implementation in myViewController.m: ‘NSMutableDictionary *dictionaryHashMap = nil;’

However, the dictionaryHashMap remains invisible to CustomUIView. As far as I can tell, it actually remains a variable which is local to myViewController…

  • 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-13T20:00:54+00:00Added an answer on June 13, 2026 at 8:00 pm

    It’s not resource-intensive to pass around the reference (pointer) to dictionaryHashMap. A pointer to an object is only 4 bytes. You could just pass it from your view controller to your view.

    But I don’t know why you even need to do that. Your view is sending a message (termTextClickedOn:didSelectTerm:) to the view controller when a term is clicked. And the view controller already has a reference to the dictionary, so it can handle the lookup. Why does the view also need a reference to the dictionary?

    Anyway, if you want to make the dictionary a global, it would be more appropriate to initialize it in your app delegate, in application:didFinishLaunchingWithOptions:. You could even make the dictionary be a property of your app delegate and initialize it lazily.

    UPDATE

    I didn’t notice until your comment that termTextClickedOn:didSelectTerm: is a class method. I assumed it was an instance method because myViewController starts with a lower-case letter, and the convention in iOS programming is that classes start with capital letters. (You make it easier to get good help when you follow the conventions!)

    Here’s what I’d recommend. First, rename myViewController to MyViewController (or better, DefinitionViewController).

    Give it a property that references the dictionary. Whatever code creates a new instance of MyViewController is responsible for setting this property.

    Give CustomUIView properties for a target and an action:

    @property (nonatomic, weak) id target;
    @property (nonatomic) SEL action;
    

    Set those properties when you create the view:

    - (void)displayDefinition:(NSString *)term {
        NSArray* definition = [self.dictionaryHashMap objectForKey:term];
        CustomUIView* definitionPopup = [[[CustomUIView alloc] init] autorelease]; // initialise a custom popup
        definitionPopup.target = self;
        definitionPopup.action = @selector(termWasClicked:);
        ...
    

    In the view’s webView:shouldStartLoadWithRequest: method, extract the term from the URL request and send it to the target/action:

    - (BOOL)webView: (UIWebView*)webView shouldStartLoadWithRequest: (NSURLRequest*)request navigationType: (UIWebViewNavigationType)navigationType {
        if ( navigationType == UIWebViewNavigationTypeLinkClicked ) {
            NSString *term = termForURLRequest(request);
            [self.target performSelector:self.action withObject:term];
            return NO;
        } 
        return YES;
    }
    

    In the view controller’s termWasClicked: method, create the new view controller and set its dictionary property:

    - (void)termWasClicked:(NSString *)term {
        MyViewController *t = [[MyViewController alloc] init];
        t.dictionary = self.dictionary;
        [t displayDefinition:term];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a diagnostic app which needs to log what the user has set
I'm writing an app in which there will be user defined categories which will
I'm writing an app which needs to send many emails and creates many user
I'm writing an app which plays host to a series of plug-ins. Those plug-ins
I am writing an app which needs to have both the traditional form of
I am writing an app which is going to be displaying images found on
I'm writing an app which will be used mainly on phones, but which some
I'm writing an iOS app which can play MIDI and output its content using
I'm writing a Rails app which has the following jasmine spec: describe buttons, ->
I'm writing an iOS app which utilizes Core Data (NSManagedObject, NSManagedObjectContext..etc) and I was

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.