UIAlertView 写在NSObject的类中没有回调

想写一个UIAlertView的管理类,就继承了NSObject, AlertHelper

写完后在ViewController中调用:

AlertHelper *alertHelper = [[AlertHelper alloc] init];
[alertHelper show];

~结果,在AlertHelper的 UIAlertView的delegate函数老是回调不到

原因:

由于是在ARC模式中,一旦show完,alertHelper就被释放了,再到回调的时候已经能够没有这个对象了。

解决方法:

改变在ViewController中写法
采用

@propertynonatomicstrong)AlertHelper *alertHelper;

调用的时候

self.alertHelper = [[AlertHelper alloc] init];
[self.alertHelper show];
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章