【问题标题】:TSAlertView not responding to delegate?TSAlertView 没有响应委托?
【发布时间】:2011-09-29 18:33:18
【问题描述】:

TSAlertView 是 TomSwift 的 https://github.com/TomSwift/TSAlertView/ 解决方案,用于呈现类似于 UIAlertView 但完全可定制的模态视图。干得好!

但是我无法响应模式对话框中的按钮按下。我将我的视图控制器设置为委托,但根本没有反应。

在我自己的 ViewController 中编写

@interface MyViewController : UIViewController <TSAlertViewDelegate> {

然后我实现

-(void) alertView: (TSAlertView *) alertView didDismissWithButtonIndex: (NSInteger) buttonIndex {
    NSLog(@"inside");
}

但它永远不会被调用。好像

[self.delegate alertView: self didDismissWithButtonIndex: buttonIndex ];

在 TSAlertView.m 中无效。

Demo 中也没有关于此的代码。有人看过 TSAlertView 吗?弄清楚如何代表按钮?谢谢!

【问题讨论】:

标签: iphone xcode delegates


【解决方案1】:

TSAlertView 的工作方式与普通的UIAlertView 几乎相同。您确定要设置委托吗?

这是我如何使用它的示例代码,所有委托方法都按预期调用:

TSAlertView *aView = [[TSAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Yes", @"No", nil];
    // <customize alertview>
[aView show];
[aView release];

您可以在- (void) dismissWithClickedButtonIndex: (NSInteger)buttonIndex animated: (BOOL) animated(在TSAlertView.m)中添加断点,看看出了什么问题,并检查代理设置是否正确。

【讨论】:

  • 完全......经过更多研究后,我意识到我没有设置委托......aView.delegate = self......谢谢!
猜你喜欢
  • 1970-01-01
  • 2014-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-29
  • 1970-01-01
  • 2012-05-06
  • 1970-01-01
相关资源
最近更新 更多