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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:36:53+00:00 2026-06-11T05:36:53+00:00

I want to manipulate views while in a for loop. I manipulate a view

  • 0

I want to manipulate views while in a for loop. I manipulate a view in the for loop, then the operations for the view are done at once after the for loop has ended. I tried to use other threads like GCD, but I noticed that a view is in the main thread. The operations are back to the main thread and they are put off after the for loop finishes.

What I want to do is update UITextView’s text while in the for loop. If I can’t operate the for loop in another thread, how can I do that? Are there other ways to do that?

  • 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-11T05:36:55+00:00Added an answer on June 11, 2026 at 5:36 am

    Solution 1: Use a timer

    In order to progressively add text to a textview, you can use an NSTimer.

    Requirements

    in your interface – the following ivars or properties:

    UITextView *textView;
    
    NSNumber *currentIndex;
    
    NSTimer *timer;
    
    NSString *stringForTextView;
    

    Assuming the string is created and the textview is set up, you can create a function to create the timer and kick it off:

    - (void) updateTextViewButtonPressed
    {
    
    
       timer = [NSTimer scheduledTimerWithTimeInterval:.5
                                         target:self
                                       selector:@selector(addTextToTextView)
                                       userInfo:nil
                                        repeats:YES];
    
    
    }
    
    - (void) addTextToTextView
    {
        textView.text = [string substringToIndex:currentIndex.integerValue];
        currentIndex = [NSNumber numberWithInt:currentIndex.integerValue + 1];
    
        if(currentIndex.integerValue == string.length)
        {
            [_timer invalidate];
            timer = nil;
        }
    }
    

    This is a basic working implementation, and you can vary it to pass in the string as userInfo for the timer, if it is not present at the class level. Then you could access it in your addTextToTextView selector with sender.userInfo. You can also adjust the timer interval and how exactly the text is added. I used half a second and character by character concatenation as an example.


    Solution 2: Use a loop

    Requirements

    NSString *string
    
    UITextview *textView
    
    - (void) updateTextViewButtonPressed
    {
        // perform the actual loop on a background thread, so UI isn't blocked
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^()
                       {
                           for (int i = 0; i < string.length; i++)
                           {
                               // use main thread to update view
                               dispatch_async(dispatch_get_main_queue(), ^()
                                              {
                                                  textView.text = [string substringToIndex:i];
    
                                              });
    
                               // delay
                               [NSThread sleepForTimeInterval:.5];
                           }
                       });
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to manipulate HTML using a custom view engine like this: protected override
If I want to manipulate a view I get it with [self viewWithTag:5]; .
I want to manipulate .zip and .rar files from C++. What libraries should I
i want to manipulate xml data simple .. thanks
I want to manipulate a games roomlist, for filtering the maps. My idea was,
Say I want to manipulate some files on a floppy drive or a USB
I start with a basic class that I want to manipulate in a List
im pulling in images from the net, and want to manipulate them a bit
I am posting some data using ajax. I want to manipulate that data and
I want to know how to open and manipulate a simple image file in

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.