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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:21:54+00:00 2026-06-13T09:21:54+00:00

I have a screen that shows details of a Newspaper (model) instance. The ViewController

  • 0

I have a screen that shows details of a “Newspaper” (model) instance. The ViewController of my screen has one property for this Newspaper model. A Newspaper instance contains several Article instances, and these Article instances must be represented as UIButtons in the screen. Tapping the UIButton must display an alert message containing the title of the Article.

What are some good ways to associate the UIButton with an Article model?
Basically, when tapping the UIButton, how do I retrieve the UIButton’s corresponding Article instance?

I currently have two approaches in mind:

  1. Override the UIButton, and add a property for the Article instance.
    • This violates the MVC model, since the view (UIButton) has a direct means of communication with the model (Article), but this will simplify button actions since the UIButton can simply call its property to know what Article instance will be used to do the action (display an alert message containing the title of the Article).
  2. Create an NSArray of UIButtons (buttonsArray), and an NSArray of Article instances (articlesArray).
    • Index 0 of the buttonsArray correspond to index 0 of the articlesArray. The Article instance associated with the tapped UIButton will be based on the button’s position in the array. In order to retrieve the corresponding Article of a UIButton, the buttonsArray must be looped until the tapped UIButton is found, and then getting the Article from the articlesArray using the same index.

Are there better ways to achieve this?

EDIT: The buttons will have animations and gesture recognizers.
Also, the information needed by the button action from the Article model does not only include the title (e.g. article position, or the object itself if it will be passed to another screen, etc.).

  • 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-13T09:21:55+00:00Added an answer on June 13, 2026 at 9:21 am

    You could use your 2nd approach, but use an NSDictionary instead of two arrays.

    Or you could use your first approach but instead of adding a property for your article instance, just add a generic string property like ‘additionalTitle’ or sth. That way you don’t create a direct dependency between your button class and your model class. You could then save the title for the alertview in this property.

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

Sidebar

Related Questions

I have a home-screen widget that has an icon that starts/so pose to bring
I have a wizard with several screens where user has to fill his/her details
I Have a Silverlight WPF app that shows tabs of data in this case
I want to show on the screen some value, that are changeable. I have
I have a screen that is supposed to have a few large sections of
I'm working on an application, and I have a screen that in my mind,
I have a splash screen that I would like to fade in, while my
I have a login screen that is branded differently for different builds of my
In an embedded program I have a screen object that needs to manage a
I have list of screen names that can be filtered by letter. The Issue

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.