UIAlertView 不响应 UIAlertViewDelegate
我正在使用 iPhone 的徽标(MobileSubstrate 插件),并为我的
@interface MyClass : NSObject
和
- (void)alertView:(UIAlertView *) 使用 .h 文件AlertView clickedButtonAtIndex:(NSInteger)buttonIndex { if(buttonIndex == 0) {
位于 .m 中,但没有任何效果,当点击警报上的按钮时,它不会调用我为每个 ButtonIndex 设置的内容。
谢谢。
编辑:这就是我所拥有的;
#import "Tweak.h"
%hook ASApplicationPageHeaderView
- (void)_showPurchaseConfirmation {
UIAlertView *alert = [[UIAlertView alloc] init];
[alert setTitle:@"title"];
[alert setMessage:@"message"];
[alert setDelegate:self];
[alert addButtonWithTitle:@"button 1"];
[alert addButtonWithTitle:@"continue"];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) { //also tried (UIAlertView *)alertView
UIAlertView *lol = [[UIAlertView alloc] init];
[lol setTitle:@"button 1"];
[lol setMessage:@"button 1"];
[lol setDelegate:self];
[lol addButtonWithTitle:@"lol"];
[lol show];
[lol release];
} else {
%orig;
}
}
%end
I'm using logos for iPhone (MobileSubstrate addons), with a .h file for my
@interface MyClass : NSObject <UIAlertViewDelegate>
and the
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex == 0) {
is in the .m, but nothing is working, when tapping the buttons on the alert, it doesn't invoke what I have set for each buttonIndex.
Thanks.
Edit: Here's what I've got;
#import "Tweak.h"
%hook ASApplicationPageHeaderView
- (void)_showPurchaseConfirmation {
UIAlertView *alert = [[UIAlertView alloc] init];
[alert setTitle:@"title"];
[alert setMessage:@"message"];
[alert setDelegate:self];
[alert addButtonWithTitle:@"button 1"];
[alert addButtonWithTitle:@"continue"];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) { //also tried (UIAlertView *)alertView
UIAlertView *lol = [[UIAlertView alloc] init];
[lol setTitle:@"button 1"];
[lol setMessage:@"button 1"];
[lol setDelegate:self];
[lol addButtonWithTitle:@"lol"];
[lol show];
[lol release];
} else {
%orig;
}
}
%end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您很可能需要在某个时候使用以下内容将您的类注册为委托
: /UIAlertViewDelegate_Protocol/UIAlertViewDelegate/UIAlertViewDelegate.html#//apple_ref/doc/uid/TP40007548" rel="nofollow">UIAlertViewDelegate 协议参考 文档说(强调我的):
You'll most likely need to register your class as the delegate at some point using something along the lines of:
As the UIAlertViewDelegate Protocol Reference docs say (emphasis mine):
在该类中定义您的警报并声明警报委托以希望它开始为您工作
Define your alert within that class and declare the alert delegate to self hope it start working to you
您只需将
%new
放在alertView
委托前面:You just need to put
%new
in front of thealertView
delegate: