继承 - 超类和子类中的 UIAlertView
Inheritance - UIAlertView in superclass and subclass
我有一个超类,我有时会在其中显示 UIAlertView 并处理委托 (clickedButtonAtIndex)。
当我有一个也处理 "clickedButtonAtIndex" 的子类时,只调用子类委托。
在这两种情况下,UIAlertView 都是这样显示的:
[[[UIAlertView alloc] initWithTitle:@"" message:@"message" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:@"Open", nil]show];
我是在做错什么,还是在超类和子类中拥有相同的委派是糟糕的设计。我以为 "delegate:self" 将它们分开了。
我可以在调试器中看到 "self" 引用了我的子类,即使我在我的超类中,所以这可能是问题所在?有什么想法吗?
我有点惊讶 'self' 在超类中调用时对子类的引用。
因此我决定为 UIAlertView 创建我自己的委托,以区别于子类的委托。这是因为我不认为:
- 子类应该知道我在超类中的私有 UIAlertView 并调用它。
- 超类应该知道我的子类委托。
随时添加您的想法:-)
我有一个超类,我有时会在其中显示 UIAlertView 并处理委托 (clickedButtonAtIndex)。 当我有一个也处理 "clickedButtonAtIndex" 的子类时,只调用子类委托。
在这两种情况下,UIAlertView 都是这样显示的:
[[[UIAlertView alloc] initWithTitle:@"" message:@"message" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:@"Open", nil]show];
我是在做错什么,还是在超类和子类中拥有相同的委派是糟糕的设计。我以为 "delegate:self" 将它们分开了。
我可以在调试器中看到 "self" 引用了我的子类,即使我在我的超类中,所以这可能是问题所在?有什么想法吗?
我有点惊讶 'self' 在超类中调用时对子类的引用。
因此我决定为 UIAlertView 创建我自己的委托,以区别于子类的委托。这是因为我不认为: - 子类应该知道我在超类中的私有 UIAlertView 并调用它。 - 超类应该知道我的子类委托。
随时添加您的想法:-)