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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:09:29+00:00 2026-05-15T19:09:29+00:00

I essentially want to give each instance of a class a unique id. So,

  • 0

I essentially want to give each instance of a class a unique id.

So, I created a static integer. I increment it each time a new object is created and then assign the value of the static variable to an ivar. But clearly I don’t understand something because, let’s say I create three objects, “thisPageNumber” (which is the instance variable) is always 3 no matter which object I reference.

More information:

This class creates a number of “Page” objects. I’d like each page to know it’s page number so that it can display the correct page art as well as perform a number of other various actions.

.h partial code:

@interface Page : UIViewController
{
    NSNumber            *thisPageNumber;
    UIImageView         *thisPageView;
    UIImageView         *nextPageView;
    UIImageView         *prevPageView;  
    UIImageView         *pageArt;
}

.m partial code:

@implementation Page

static int pageCount = 0;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        pageCount++;
        thisPageNumber = pageCount;
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    CGRect defaultFrame = CGRectMake(0.0, 0.0, 1024.0, 768.0);

    if (thisPageView == nil) {
        thisPageView = [[UIImageView alloc] 
                        initWithImage:[UIImage 
                                       imageNamed:[NSString stringWithFormat:@"Page%i.png", [thisPageNumber intValue]]]];
        thisPageView.frame = defaultFrame;
        [self.view addSubview:thisPageView];
    }

    if (nextPageView == nil && [thisPageNumber intValue] < BOOK_PAGE_COUNT) {
        nextPageView = [[UIImageView alloc] 
                        initWithImage:[UIImage 
                                       imageNamed:[NSString stringWithFormat:@"Page%i.png", [thisPageNumber intValue]+1]]];
        nextPageView.frame = defaultFrame;
        [self.view addSubview:nextPageView];
    }

    if (prevPageView == nil && [thisPageNumber intValue] > 1) {
        prevPageView = [[UIImageView alloc] 
                        initWithImage:[UIImage 
                                       imageNamed:[NSString stringWithFormat:@"Page%i.png", [thisPageNumber intValue]-1]]];
        prevPageView.frame = defaultFrame;
        [self.view addSubview:prevPageView];
    }    
}
  • 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-15T19:09:30+00:00Added an answer on May 15, 2026 at 7:09 pm

    I’m not sure why the compiler didn’t complain, but part of your problem is here:

    thisPageNumber = pageCount;
    

    NSNumber is an object. To set it to the current pageCount value, use

    thisPageNumber = [[NSNumber alloc] initWithInt:pageCount];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I essentially want to display a screen whenever the screen is unlocked regardless of
I've gotten myself into a situation that seems fairly unusual, and essentially want to
Essentially I want a border-less, black window which I can set the location and
Essentially I want to suck a line of text from a file, assign the
I have 3 date range forms on my site. Essentially I want to hide
Essentially what I want to do is to apply additional CSS classes to individual
If I want to essentially grep every line ever in the repository, is there
Essentially, what I want to do (in DirectX) is to take two partially-transparent images
I want to store a list of numbers (essentially, a set in mathematical terms)
I want to implement a view in an iPhone application that is essentially like

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.