我正在尝试将UIButton放入iPhones MobileSMS.app(消息应用)。它成功出现在视图中,但当你按下它时,它当然会崩溃,因为它没有调用任何目标类并挂钩方法。我要挂钩的目标类和方法是在下面的第二个代码中,如何在按下按钮时调用它? (我的主要目标是在对话视图中放置一个按钮,当它被点击时,它将强制SMS而不是自动使用iMessage。)
#import <UIKit/UIKit.h>
#import <ChatKit/ChatKit.h>
@interface CKTranscriptCollectionViewController : UIViewController
@end
%hook CKTranscriptCollectionViewController
-(void)loadView {
%orig;
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"SMS" forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, 50, 100);
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
-(void)buttonPressed {
NSLog(@"Button Pressed!");
}
%end
我想在按下按钮时调用的类和方法(属于标题&#34; ChatKit / CKConversation.h&#34;):
%hook CKConversation
-(BOOL)forceMMS {
return TRUE;
}
%end
答案 0 :(得分:2)
它崩溃,因为它编写了一个参数。尝试将方法定义更改为:
-(void)buttonPressed:(id)sender
或将目标更改为:
[button addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
答案 1 :(得分:0)
带有徽标的Opsss定义您必须编写的新动作/方法
在此操作或方法之前%new
我建议你创建一个私有类来使用这个动作
[self buttonPressed];
私人班级应该是
@interface CKTranscriptCollectionViewController (TWEAKNAME)
-(void)buttonPressed;
@end
所以你的代码应该是
#import <UIKit/UIKit.h>
#import <ChatKit/ChatKit.h>
@interface CKTranscriptCollectionViewController : UIViewController
@end
@interface CKTranscriptCollectionViewController (TWEAKNAME)
-(void)buttonPressed;
@end
%hook CKTranscriptCollectionViewController
-(void)loadView {
%orig;
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"SMS" forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, 50, 100);
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
%new
-(void)buttonPressed {
NSLog(@"Button Pressed!");
}
%end
好运