我有一个MYView类(UIView的子类),我将MyView添加到我当前的ViewController中作为子视图。如果触发TouchUpInsideEvent,MyView有一个调用委托方法的按钮。我的问题是,当我在按键敲击时进入的委托方法,但如果我火TouchUpinsideEvent prgramaticaaly它不调用委托method.Here是我的代码:UITouchUpInside不调用委托方法
MyView.h
@protocol MyViewDelegate;
@interface MyView : UIView
@property(nonatomic,assign)id<MyViewDelegate> delegate;
@protocol MyViewDelegate <NSObject>
- (void)selctedOption:(MyView *)slideView withOption:(UILabel *)option withIndex: (NSInteger *)labelIndex;
@end
MyView.m
toggleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[toggleButton setTitle:@"" forState:UIControlStateNormal];
//adding target works fine it goes to the finishedDraggingVertical:withEvent method and from there I am calling the delegate method
[toggleButton addTarget:self action:@selector(finishedDraggingVertical:withEvent:)
forControlEvents:UIControlEventTouchUpInside];
toggleButton.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, height);
toggleButton.backgroundColor=[UIColor colorWithRed:0.1 green:1.1 blue:0.3 alpha:0.2];
[toggleButton.layer setBorderWidth:10.0];
[toggleButton.layer setBorderColor:[[UIColor lightGrayColor] CGColor]];
toggleButton.layer.cornerRadius=10.0;
[self addSubview:toggleButton];
**//But If I fire the event programatically this doesn't work it goes to finishedDraggingVertical:withEvent but from there it does not go to the delegate method.**
[toggleButton sendActionsForControlEvents:UIControlEventTouchUpInside]
MyViewController.h
@interface MyViewController : UIViewController <MyViewDelegate>
MyViewController.m
//这里我加入MyView的贯彻委托方法
- (void)viewDidLoad
{
[super viewDidLoad];
MyView *myiew1=[[MyView alloc]init];
myiew1.delegate=self;
[self.view addSubview:slideView1];
}
你在哪里分配代表? – Rakesh 2013-03-14 07:44:08
在我的视图控制器 – user1787741 2013-03-14 08:17:41
你可以显示MyViewDelegate的完整协议声明,以及你在哪里试图调用委托? – Fogmeister 2013-03-14 08:26:57