프로그램/iOS

iOS 코드로 버튼에 이벤트 주기

잡식성초보 2016. 2. 26. 17:41

코딩시에 보통 테이블뷰를 사용하여 cell을 만들 경우 UITableViewCell에 있는 Oulet들에 이벤트를 주는 경우 나같은 경우 코드로 작성한다. 다르게 하는 방법이 있는지는 잘 모르겠다.


[cell.ClickButton addTarget:self action:@selector(실행시킬 함수) forControlEvents:어떤 이벤트인지]; 


ex)[cell.ClickButton addTarget:self action:@selector(CellButton:) forControlEvents:UIControlEventTouchUpInside];


그리고 이번트이 무엇인지 확인 하기 위해서는 보통 tag값을 활용하여 알아낸다.

cell.ClickButton.tag = 값



- (void) CellButton : (id)sender {

self.Tag = (int)sender.tag;

}

반응형