문제

Note: This code is not an exact replica of the original code, but illustrates (with good accuracy) what the issue is, and what my intentions with the code are.

I have added a button to DaClass1's view (this works fine):

%hook DaClass1

-(id)DaView {
    UIButton *xButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [xButton addTarget:self action:@selector(dismissWithAnimation:YES:nil)
      forControlEvents:UIControlEventTouchUpInside];
    [xButton setBackgroundImage:[UIImage imageWithContentsOfFile:@"/Hello.png"] forState:UIControlStateNormal];
    xButton.frame = CGRectMake(0, 0, 30, 30);
    [self addSubview:xButton];
    return %orig;
}

%end

But the UIButton's action: (dismissWithAnimation:YES:nil) is actually from another class:

%hook DaClass2
    -(void)dismissWithAnimation:(int) reason:(int) {
        //someCodeHere...
    }
%end

How may I call dismissWithAnimation in DaClass2 from my UIButton's action: when the UIButton is in DaClass1?

도움이 되었습니까?

해결책

You can make a %new function that calls dismissWithAnimation in DaClass2.

%hook DaClass1

//Your Code...

%new

-(void)dismissIt {
    [[%c(DaClass2) sharedInstance] dismissWithAnimation:YES:nil];
}

%end

and set the xButton's action: to "dismissIt":

[xButton addTarget:self action:@selector(dismissIt) forControlEvents:UIControlEventTouchUpInside];

다른 팁

Do you mean that the @selector(dismissWithAnimation:YES:nil) method is in the class DaClass2?

Then do:

[xButton addTarget:(instance of DaClass2) action:@selector(dismissWithAnimation:YES:nil) forControlEvents:UIControlEventTouchUpInside];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top