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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:20:06+00:00 2026-06-17T19:20:06+00:00

I want to update the contents of this UITextView with this NSMutable array by

  • 0

I want to update the contents of this UITextView with this NSMutable array by adding some delay to it.

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



int index = arc4random() % [myArray count];

myTextView.text = [myArray objectAtIndex:index];

I want to display this NSMutable array one after other with some delay in UITextView.

Is there some way to display array in UITextView with some delay.

Please help

  • 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-17T19:20:07+00:00Added an answer on June 17, 2026 at 7:20 pm

    Why you should use a timer

    The correct way of doing this would be to use a repeating timer. The timer is configured to repeat and call a certain method every second.

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

    Inside your (new) updateText method you would generate the random number and update the text.

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

    This is a clean solution that is almost self documenting.


    Why you shouldn’t loop and perform after delay.

    It is true that you could do this with performSelector:withObject:afterDelay: or dispatch_after() but it is a easy to get wrong and is the actual working solution is more complex and harder to understand.

    If you think that you can just loop a certain number of times and inside call either of these then you are going to see something funny. Both these methods are asynchronous and will not wait for the call to be called. They are merely scheduling it to happen a specified time from "now".

    What looping and calling asynchronous methods do

    Loop 
     0    |----- 1s wait -----| |update|
     1     |----- 1s wait -----| |update|
     2      |----- 1s wait -----| |update|
     3       |----- 1s wait -----| |update|
        ...
     ----------- time --------------------->
    

    The result of this, as you can imagine, is that nothing will happen for one second. Then all the scheduled calls are going to happen all at once.

    This is actually equal to performing the entire loop after one second.

     |----- 1s wait -----| Loop:
                             0  |update|
                             1   |update|
                             2    |update|
                             3     |update|
                                ...
     ----------- time --------------------->
    

    You could make this work if you instead scheduled the next call after each update

     |----- 1s wait -----| |update| |----- 1s wait -----| |update| ...
     ----------- time --------------------->
    

    For this to happen you would have to schedule the next update in the previous update.

    - (void)updateText {
        int index = arc4random() % [myArray count];
        myTextView.text = [myArray objectAtIndex:index];
        [self performSelector:@selector(updateText) 
                   withObject:nil
                   afterDelay:1.0];
    }
    

    This would do the exact same thing as the repeating timer but has two main disadvantages.

    1) It is less intuitive.

    In the timer example you would only have to read the timer code to understand that the text would update every second. In this case you would just call updateText. It is not intuitive by reading that code without looking at the implementation of updateText that this is a repeating process.

    2) It gets even more complex if you want it to stop.

    You can keep a pointer to an NSTimer and make it stop by simply calling [myTimer invalidate];. The code that uses either performSelector:... or dispatch_after() doesn’t yet support it and if it was built to support that it would be even more complex and less intuitive.

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

Sidebar

Related Questions

Hey guys quick question, I want to update the contents of a div with
i have ios application with xcdatamodeld, i want update some data so need a
I want to update the lastlogin column value .i wrote the code like this
i am fairly new to django and i want to update some of my
simple question maybe but can't find solution. I have button for refresh/update some contents
i have a NumericUpDown control and want to update its contents from the registry.
I have a div whose contents I want to update by AJAX. To make
I want to update the contents of a TBODY (not the entire TABLE, because
I want to update the contents of my databind Ul-Li list with the searched
I am using PrimeFaces 3.0.M4. I want to update the contents of PrimeFaces layout

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.