我有几个地方需要显示警惕,以同样的方式处理解雇行动,即把他们带往同一观点的控制人员。 在所有这些地方,我不是重复具体的警示守则,而是另设一个类别,如:
AlertUtility.h:
@interface AlertUtility : NSObject {
}
- (void) displayAlert;
@end
AlertUtility.m:
@implementation AlertUtility {
- (void) displayAlert {
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:... message:...
delegate:self cancelButtonTitle:... otherButtonTitles:nil] autorelease];
[alert show];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
// Create another view controller and display its views
[self release] // Release current object because I m not releasing it where I create it
}
}
在我需要利用这一警示的地方(即在我的《意见》中),我有:
MyViewController.m:
AlertUtility *utility = [[AlertUtility alloc] init];
[utility displayAlert];
As you can see, I am not releasing the utility object here (which I should since I own it), but rather in the didDismissWithButtonIndex method of the AlertUtility class. I am clearly missing something here.
我曾尝试自动解救该用途物体,但随后,在将McDismissWithButtonIndex方法提上该用途物体时,该物体已经释放(因为自动释放)。
我在尝试展示 静态警报方法(并用<代码>[AlertUtility showAlert];,但此后从未使用过DismissWithButtonIndex。
我是否应该像现在一样,从DismissWithButtonIndex方法中释放目前的物体,或者在我的《意见》主计长中(不为目前这一类别创造警觉性财产)释放该物体?
感谢!
EDIT Should I use the Singleton pattern instead maybe?