ios - Objective-C: blocks and ARC -


i have created utility class uialerts. using blocks

my code, user should create, looks this:

myalertmessage * = [[myalertmessage alloc] initwithtitle:@"hello" withmessage:@"world"];  [a addbutton:button_ok withtitle:@"ok" withaction:^(void *action) {         nslog(@"button ok @ index 0 click"); }];  [a addbutton:button_cancel withtitle:@"cancel" withaction:^(void *action) {         nslog(@"button cancel @ index 1 click"); }];  [a show] 

full class can seen here: https://github.com/martinperry/uialert

now, if this, after [a show] arc destroys class, blocks no longer working , gives me error. have solved creating singleton class holds reference created myalertmessage (message ads , destroys manager). correct solution or should done better, without singleton manager?

manager , appropriate class can found here: https://github.com/martinperry/uialert/blob/master/uialert/myalertmessage.m

the example code posted uses local variable create myalertmessage object. since local variable, goes out of scope execution leaves current set of braces (method, if statement, whatever.) happens nobody has strong reference object, gets deallocated.

make myalertmessage variable instance variable , set nil when done it.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -