objective c - How To Use Variable Value Outside Block? -
objective c - How To Use Variable Value Outside Block? -
i have next code checking connectivity of app. want display connectivity status in uilabel on custom uiview slides in when connectivity status changes.
[edit]
__block nsstring * strconnectivitystatus = @""; [[afnetworkreachabilitymanager sharedmanager] startmonitoring];
[end edit]
[[afnetworkreachabilitymanager sharedmanager] setreachabilitystatuschangeblock:^(afnetworkreachabilitystatus status) { nslog(@"reachability: %@", afstringfromnetworkreachabilitystatus(status)); strconnectivitystatus = afstringfromnetworkreachabilitystatus(status); switch (status) { case afnetworkreachabilitystatusreachableviawwan: viewconnectivitystatus.hidden = false; lblconnectivitystatus.text = afstringfromnetworkreachabilitystatus(status); case afnetworkreachabilitystatusreachableviawifi: viewconnectivitystatus.hidden = false; lblconnectivitystatus.text = afstringfromnetworkreachabilitystatus(status); break; case afnetworkreachabilitystatusnotreachable: viewconnectivitystatus.hidden = false; lblconnectivitystatus.text = afstringfromnetworkreachabilitystatus(status); default: viewconnectivitystatus.hidden = false; lblconnectivitystatus.text = afstringfromnetworkreachabilitystatus(status); break; } }];
and phone call custom uiview slides position:
olslidingmessagevc *msgconnectivityvc = [[olslidingmessagevc alloc] initwithtitleandposition:@"status" message:strconnectivitystatus msgheight:&viewheight msgwidth:&viewwidth msgxpos:&viewxpos msgypos:&viewypos];
but strconnectivitystatus blank cannot access value outside of block.
how can status appear on uilabel on uiview?
then block not called synchronously, strconnectivitystatus
won't set anywhere outside block.
just create strconnectivitystatus
local variable within block , perform action need within block.
objective-c uiview ios8 objective-c-blocks
Comments
Post a Comment