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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:20:12+00:00 2026-05-25T18:20:12+00:00

This is a very elemental question about object-orientated programming- so sorry in advance if

  • 0

This is a very elemental question about object-orientated programming- so sorry in advance if this is obvious.

I have a view and add several objects to this view (as subviews). I do this programatically. Every object get’s an individual ID so that I can later tell objects apart (in this case it is the int position). This is my code:

    for (int i=0; i < [directories count]; i++) {

    NSLog(@"%i", i);

    Notebook *aBook = [[Notebook alloc] initWithName:aName withPosition:i];
    [self.view addSubview:aBook];
    [aBook release];
    [aName release];

}

After this, a have a view with several objects attached to it. My question is how I can get to these objects now. What if I wanted to find out the name or any other variable saved in this object? E.g. how would I get the nameOfBook if I knew what the stackPosition is? Here is the header of my object notebook:

 #import <Foundation/Foundation.h>

@interface Notebook : UIView

{
    NSString *nameOfBook;
    int stackPosition;
    int bookWidth;
    int bookHeight;
    int xPosition;
    int yPosition;

}

@property (nonatomic, retain) NSString *nameOfBook;
@property int stackPosition;
@property int bookWidth, bookHeight, xPosition, yPosition;

-(id)initWithName:(NSString *)name withPosition:(int)position;
-(void)putOnScreen;

@end
  • 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-05-25T18:20:12+00:00Added an answer on May 25, 2026 at 6:20 pm

    You can create an array or dictionary of your Notebook objects and add each one into there. Then you can reference them later on by getting the array / dictionary object.

    So create instance var for your array….

    NSMutableArray *myBooks;
    

    And then add your objects into the array in your loop….

    [myBooks addObject:aBook];
    

    And when you want to retrieve it later (using 0 based index)….

    Notebook *theBook = [myBooks objectAtindex:myIndexNumberHere];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm sorry for this very newbish question, I'm not much given into web development.
Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
Important : Please see this very much related question: Return multiple values in C++
I have this very simple example that I am using to learn structs in
I have a question about storing site configuration data. We have a platform for
I have a question about how garbage collection might be handled in a linq
This is a very general question but it's based on a specific problem. I've
I have a question about optimization, but more on the browser/client side. I am
This question is very similar to that posed here . My problem is that
sorry, I did not find something useful when searching google. Very basic question, mainly

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.