【问题标题】:How can I get my UISwitch to call this method? (using theos)如何让我的 UISwitch 调用此方法? (使用theos)
【发布时间】:2014-09-04 18:19:30
【问题描述】:

如何让我的 UISwitch 调用此函数:https://ghostbin.com/paste/y2xrc 开启时,返回 FALSE;当它关闭时。 (我用theos编译)

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

#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

【问题讨论】:

    标签: ios objective-c iphone theos


    【解决方案1】:

    对于 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

    【讨论】:

    • 我不太确定该怎么做?我知道将您的代码添加到 viewdidload;但是我如何让它执行我发布的链接中的操作?
    • 我需要更多地了解您的类结构和运行时可用的实际对象。我的猜测是在视图控制器中添加一个方法来切换对话对象的属性。
    【解决方案2】:

    你可以试试这个:

    [yourSwitchObject addTarget:self action:@selector(generateLegendaryMessage:) forControlEvents:UIControlEventValueChanged]; 
    
    - (void)generateLegendaryMessage:(id)sender 
    {
        NSLog("Its gonna be legen...... wait for it ...... dary !!!!!!!");
    }
    

    【讨论】:

      猜你喜欢
      • 2014-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多