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

  • Home
  • SEARCH
  • 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 974285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:24:44+00:00 2026-05-16T03:24:44+00:00

// Declare index in Header.h index=0; – (IBAction)next { index++; // Set imageCount to

  • 0
// Declare index in Header.h

index=0;

- (IBAction)next {
    index++;
    // Set imageCount to as many images as are available
    int imageCount=2;
    if (index<=imageCount) {
        NSString* imageName=[NSString stringWithFormat:@"img%i", index];
        [picture setImage: [UIImage imageNamed: imageName]];
    }
}

Where do I declare index in my header file and how?

  • 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-16T03:24:44+00:00Added an answer on May 16, 2026 at 3:24 am

    If index is used only within the -next method, you can define a static variable.

    - (IBAction)next {
        static int index = 0;    // <-- here
        index++;
        // Set imageCount to as many images as are available
        int imageCount=2;
        if (index<=imageCount) {
            NSString* imageName=[NSString stringWithFormat:@"img%i", index];
            [picture setImage: [UIImage imageNamed: imageName]];
        }
    }
    

    Note that all instances will share the same index.

    But I believe it’s better to make index as an ivar, e.g.

    @interface ... {
       ...
       int index;
       ...
    }
    

    it is automatically initialized to 0 when the instance is constructed, and methods other than next can use the index. Also, each instance will have its own index.

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

Sidebar

Related Questions

I have been given a header with the following declaration: //The index of 1
I am declaring an array of NSString* in a header file of a class.
The code works when I declare $lang like this (at the top of the
I have the following chunk of a header file BKE_mesh.h: /* Connectivity data */
According to the Qt documentation, QVariant::operator== does not work as one might expect if
I have a map that represents a DB object. I want to get 'well
I found this in the code I'm working on at the moment and thought
I just finished the Netbeans introduction to Hibernate tutorial ( http://netbeans.org/kb/docs/web/hibernate-webapp.html#01 ) and I
I have a menu uses nested unordered lists to give the appearance of a

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.