如何让我的UISwitch调用此方法? (使用theos)

时间:2014-09-04 18:19:30

标签: ios objective-c iphone theos

如何让我的UISwitch调用此函数:https://ghostbin.com/paste/y2xrc打开时,返回FALSE;什么时候关掉。 (即时使用theos进行编译)

(我在Messages.app(MobileSMS.app)中切换显示“CKTranscriptCollectionViewController”内部,现在我希望它在打开或关闭时执行某些操作,这是我在上面的链接中发布的内容)。< / p>

#import <UIKit/UIKit.h>
#import <ChatKit/ChatKit.h>
#import <ChatKit/CKConversation.h>

@interface CKTranscriptCollectionViewController : UIViewController
@property (nonatomic, strong) UISwitch *mySwitch;
- (void)loadView;
@end

%hook CKTranscriptCollectionViewController

- (void)viewDidLoad {   
    %orig;
    UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(10, 10, 51, 31)];
    [mySwitch setOn:NO animated:YES];
    [self.view addSubview:mySwitch];
}

%end

2 个答案:

答案 0 :(得分:0)

对于UISwitch,您应该为UIControlEventValueChanged

添加目标
[mySwitch addTarget:self action:@selector(switchToggle) forControlEvents:UIControlEventValueChanged];

相应地替换你的目标和行动。调用选择器时,您需要检查开关的值。

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIControl_Class/Reference/Reference.html#//apple_ref/c/econst/UIControlEventValueChanged

答案 1 :(得分:0)

你可以试试这个:

[yourSwitchObject addTarget:self action:@selector(generateLegendaryMessage:) forControlEvents:UIControlEventValueChanged]; 

- (void)generateLegendaryMessage:(id)sender 
{
    NSLog("Its gonna be legen...... wait for it ...... dary !!!!!!!");
}