2010-08-10 5 views
0

UIButton의 @selector 메서드에서 인수를 전달하는 방법은 무엇입니까?예를 들어 @selector에서 인수를 전달하려면 어떻게해야합니까?

-(void)loadView{ 
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom]; 
    btn1.tag=1; 
    [btn1 addTarget:self action:@selector(showRestaurant:tag:) forControlEvents:UIControlEventTouchDown]; 
    btn1.frame = CGRectMake(2370.828125,1020.015625,35,34); 
    [imageView addSubview:btn1]; 
} 

-(void)showRestaurant:(NSInteger)tag{ 
    NSLog(@"x=%d",tag); 
} 

여기이 메소드 showRestaurant에 대한 태그 값을 가져 오려고합니다.

친절히 도와주세요!

답변

4

당신은 메소드 서명과 일치해야

@selector(showRestaurant:) 

-(void)showRestaurant:(UIButton*)btn 
{ 
    NSLog(@"tag=%d",btn.tag); 
} 

선택기를 사용한다 뺀 방법에있어서 변수의 "내부 이름".