I have a problem with IBAction delegate. I create button in xib file by Interface Builder and want to use it in another controller.
Button is clickable and I don't see any error but it don't show Alert or NSLog. If I try to do NSLog in LetterView.m, It's work perfectly fine but not in ViewController. What should i do?
Thanks for help.
What I am doing currently is:
LetterView.h
#import <UIKit/UIKit.h>
@class LettersView;
@protocol ButtonHint <NSObject>
-(void)hintButtonView:(LettersView*)letterView;
@end
@interface LettersView : UIView @property (strong, nonatomic) IBOutlet UIView *lettersView;
- (IBAction)hintButton:(id)sender;
- (IBAction)removeButton:(id)sender;
@property (nonatomic, assign) id <ButtonHint> hintDelegate;
@end
LetterView.m
-(IBAction)hintButton:(id)sender {
[self.hintDelegate hintButtonView:self];
}
ViewController.h
@interface GameViewController : UIViewController <ButtonDisplayChar, ButtonHint>
ViewController.m
-(void)hintButtonView:(LettersView *)letterView {
NSLog(@"DSfdfsadasda");
[self addAlert:@"HINT" andMessage:helpstr andButton:@"Thanks"];
}
You can do in other View controller by adding target of that Button example : in your xib have button.
Use that button as target in other view controller.
example : first in view controller
var letterVw : LetterView?
letterVw.myFirstButton.addTarget(self, action: #selector(myClass.pressed(_:)), forControlEvents: .TouchUpInside)
than
func pressed(sender: UIButton!) {
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.