简体   繁体   English

TSAlertView不响应委托吗?

[英]TSAlertView not responding to delegate?

TSAlertView is TomSwift's https://github.com/TomSwift/TSAlertView/ solution to present modal views that look like UIAlertView but fully customizable. TSAlertView是TomSwift的https://github.com/TomSwift/TSAlertView/解决方案,用于呈现类似于UIAlertView但可完全自定义的模态视图。 Good work! 干得好!

However I fail to respond to button press in the modal dialog. 但是,我无法响应模式对话框中的按钮按下。 I set up my viewcontroller as delegate, but there is simply no reaction. 我将我的viewcontroller设置为委托,但是没有任何反应。

In my own ViewController I write 在我自己的ViewController中,我写

@interface MyViewController : UIViewController <TSAlertViewDelegate> {

and then I implement 然后我实现

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

but it never gets called. 但它永远不会被调用。 It seems like 这好像是

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

in TSAlertView.m has no effect. 在TSAlertView.m中无效。

Also there is no code about this in the Demo. 演示中也没有与此相关的代码。 Anybody ever looked at TSAlertView? 有人看过TSAlertView吗? Figured out how to be delegate for the buttons? 想通了如何委派按钮? Thanks! 谢谢!

TSAlertView works pretty much the same way as a normal UIAlertView . TSAlertView工作方式与普通UIAlertView几乎相同。 Are you sure you're setting the delegate? 您确定要设置代表吗?

Here's a sample code on how I was using it, with all the delegate methods getting called as expected: 这是关于我如何使用它的示例代码,所有委托方法均按预期方式被调用:

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

You can add a breakpoint in - (void) dismissWithClickedButtonIndex: (NSInteger)buttonIndex animated: (BOOL) animated (in TSAlertView.m ) and see what goes wrong and check if the delegate was set correctly. 您可以在- (void) dismissWithClickedButtonIndex: (NSInteger)buttonIndex animated: (BOOL) animated (在TSAlertView.m )中添加断点,并查看出了什么问题并检查委托是否设置正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM