Question

I need to show log outputs in a textview then and there in my app. I tried using performSelector inside my sequence but it did not work as I thought it would. Can someone show me how to do it?

For example, when I click a button, I do lot of operations underneath, and I want to display the logs in the textview then and there, not after the entire operation is done.

Plus can't I call performSelector more than once inside the same sequence?

Below is the sequence inside the button click:

- (IBAction)Write:(id)sender {

 //do some action here
 DisplayString = @"Seq1 pass"
 [self performSelector:@selector(updateviewText) withObject:nil afterDelay:0];
 //do some more action
 DisplayString = @"Seq2 pass"
 [self performSelector:@selector(updateviewText) withObject:nil afterDelay:0];
 ....
}

This the updateviewText part:

-(void)updateviewText {
        dispatch_queue_t queueNew = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
        dispatch_async(queueNew,^ {

        dispatch_async(dispatch_get_main_queue(),^{
            [self.txtViewUseCaseLOG setText:[NSString stringWithFormat:@"%@\n%@", 
                                       self.txtViewUseCaseLOG.text,DisplayString ]];             
        });           
    });
}

The DisplayString is a global variable here.

This code doesn't setText to the textview then and there... But as I asked earlier I need those messages then and there...

No correct solution

OTHER TIPS

You can't update the UI asynchronously. If you're doing task asynchronously and want to update the UI you have to use dispatch_sync.

And why would you when you're doing something asynchronously open another asynchronous task?

Next thing is that if you're only using DisplayString in these two methods you might better add a NSString parameter to updateViewText so you don't need the global variable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top