0

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?

Krishnabhadra
  • 34,169
  • 30
  • 118
  • 167
Kiron
  • 278
  • 5
  • 18

2 Answers2

3

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

Community
  • 1
  • 1
Samkit Jain
  • 2,523
  • 16
  • 33
  • Ok but i have to return a value from that function. When i use the selector method i am not able to get the return value – Kiron Aug 12 '13 at 09:43
  • 1
    I found out the solution by assigning the value to a variable by using the method provided by Samkit Jain – Kiron Aug 13 '13 at 10:40
0

You can use GCD blocks Try this.

Community
  • 1
  • 1
Rahul Mane
  • 1,005
  • 18
  • 33