Frage

I have a function call and some coding statements after the function. These statements should be called only after the function is executed completely How can it be achieved? Currently the statements are executed before the function is executed completely.

For example

NSInteger integerRestValue=[self buttonRestNameTag];
buttonRestNames.titleLabel.text=[[arrayGuessList objectAtIndex:integerRestValue]valueForKey:@"Name"];

Here the buttonRestNameTag function is called and before the execution is completed the buttonRestNames title label is set which cause it to crash.

How can this be resolved?

War es hilfreich?

Lösung

You may have initialized another Thread inside your function buttonRestNameTag. Check that thing.

Or Try to use this function :

[self performSelectorOnMainThread:@selector(functionName) withObject:nil waitUntilDone:YES];

Hope this helps.

Edit for Kiron :

Make a variable in class and put returned value in that and access that variable.

This is helpful link to do this

iphone - performSelectorOnMainThread with return value

Andere Tipps

You can use GCD blocks Try this.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top