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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:08:00+00:00 2026-06-17T20:08:00+00:00

How to increment currentindex so that textview can be updated in a sequence manner

  • 0

How to increment currentindex so that textview can be updated in a sequence manner than randomly.

- (void)viewDidLoad{
myArray = [[NSMutableArray alloc]initWithObjects:@"String1",@"String2",@"String3",@"String4", @"String5",..... nil];  

[NSTimer scheduledTimerWithTimeInterval:2.0
                                 target:self
                               selector:@selector(updateText:)
                               userInfo:nil
                                repeats:NO];

self.textView.font = [UIFont fontWithName:@"Baskerville-Bold" size:22];

self.textView.textAlignment = NSTextAlignmentCenter;

self.textView.backgroundColor = [UIColor clearColor];

self.textView.textAlignment =  NSTextAlignmentCenter;
self.textView.text = @"String1";
self.textView.scrollEnabled = NO;

self.textView.editable = NO;

self.textView.userInteractionEnabled = NO;

[baseView addSubview: self.textView];

} 

- (void)updateText:(NSTimer *)theTimer {
int index = arc4random() % [myArray count];
myTextView.text = [myArray objectAtIndex:index];

}

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

    Instead of making index a local variable, make it a property

    @property (nonatomic) NSInteger index;

    in viewDidLoad initialize it to 0;

    Then use it like this only:

               - (void)updateText:(NSTimer *)theTimer 
            {
                NSLog(@"myArray count is %d",[myArray count]);
                CFShow((__bridge CFTypeRef)(myArray));
    
                if (index < [myArray count])
                {
                    NSLog(@"%d value is %@",index,[myArray objectAtIndex:index]);
                    myTextView.text = [myArray objectAtIndex:index];
                    index++;
                }
                else
                    index = 0;
                }
        }
    

    and i hope you are using Timer like this :

    self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(yourFunctionToUpdateTimer) userInfo:nil repeats:NO];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I increment a list in python.In the following case So that means
I am trying to increment and decrement the middle textview via buttons on the
Is Interlocked.Increment(ref x) faster or slower than x++ for ints and longs on various
How can I increment an integer inside a foreach loop (like in C++) This
How can I increment refcount of the HMODULE returned by the GetModuleHandle ? Can
Is there any auto increment property for field in Oracle without using sequence and
How do I increment a Integer's value in Java? I know I can get
how can i increment my css ID using php programmatically? foreach ($query_cat->result() as $row_cat)
I want to increment an integer that gets incremented in a timer event handler
void increment(ref int i) { ++i; } class Class { immutable int member; this(int

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.