2011-10-20 1 views
0

페이지 스크롤로 두 개의 버튼을 만들었습니다. 이제 하나의 버튼을 클릭하여 다른 버튼을 볼 수 있습니다. 현재 버튼의 동작 방법을 수행 할 때 다른 버튼의 색인을 얻는 방법은 무엇입니까?페이지를 스크롤하는 동안 버튼 이벤트가 올바르게 작동하지 않습니다.

 for (int i = 0 ; i < numberOfPages ; i++) 
{ 

    pageFrame = CGRectMake(i * scrollView.bounds.size.width, 0.0f, scrollView.bounds.size.width, 416) ; 


    btnSettingButton=[[UIButton alloc]initWithFrame:pageFrame ]; 
    [ btnSettingButton setFrame:CGRectMake(i * (scrollView.bounds.size.width)+50, 260, 20, 20)]; 
    btnSettingButton.tag=i; 
    [btnSettingButton setImage:[UIImage imageNamed:@"Settings Icon.png"] forState:UIControlStateNormal]; 

    [scrollView addSubview:btnSettingButton]; 
    [btnSettingButton setHidden:YES]; 
    // [btnSettingButton release]; 


    UIButton *btnCheckButton=[[UIButton alloc]initWithFrame:pageFrame ]; 
    [ btnCheckButton setFrame:CGRectMake(i * (scrollView.bounds.size.width)+250, 260, 20, 20)]; 
    [btnCheckButton setImage:[UIImage imageNamed:@"NO.png"] forState:UIControlStateNormal]; 


    [btnCheckButton addTarget:self action:@selector(checkBoxClicked:) forControlEvents:UIControlEventTouchUpInside]; 

    // [btnCheckButton addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventTouchUpInside]; 


    [scrollView addSubview:btnCheckButton]; 
    [btnCheckButton release]; 

답변

1

UIButtontag는 특성을 갖는다 : 여기서

는 버튼을 생성하기위한 코드이다. 태그에 카운터를 설정하고 클릭 한 버튼을 확인할 수 있습니다.

btnCheckButton.tag = i; 

작업 :

보기 사용 방법 viewWithTag:

을 버튼을 찾기 위해
-(void)checkBoxClicked:(UIButton*)sender{ 
    if (sender.tag == 0){//button into the first page 
    } 
    if (sender.tag == 1){//second 
    } 
} 

관련 문제