我正在尝试将UIButton放入iPhones MobileSMS.app (消息应用程序)中。它成功地出现在视图中,但当您按下它时,它当然会崩溃,因为它没有调用任何目标类和挂钩方法。我想挂接的目标类和方法在下面的第二段代码中,我如何实现在按钮被按下时调用它?(我的主要目标是在对话视图中放置一个按钮,当它被点击时,它将强制短信,而不是自动使用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点击按钮时我想调用的类和方法(属于标题"ChatKit/CKConversation.h"):
%hook CKConversation
-(BOOL)forceMMS {
return TRUE;
}
%end发布于 2014-09-10 15:29:30
它崩溃是因为它探测到了一个参数。尝试将方法定义更改为:
-(void)buttonPressed:(id)sender 或将目标更改为:
[button addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];发布于 2014-09-12 05:24:32
使用徽标定义您必须编写的新操作/方法的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!");
}
%endGoodLuck
https://stackoverflow.com/questions/25759174
复制相似问题