을 눌렀을 때 설정 특성 및 사용 나는 다음 2 개 버튼 같은 클래스의 모두가하고있는 UIButton는이 세포에서 내 .H 파일있는 UIButton - 버튼을
@interface CellButton : UIButton
@property (nonatomic,retain) CellButton *property;
에 셀 버튼을 불렀다 btn1.property = 0;
및 btn2.property = 1;
이 셀을 indexPath의 행으로 설정합니다.
-(void)BtnClicked:(UIButton*)sender{
DiningHallTableViewController *dtvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DiningHallTableViewController"];
[self.navigationController pushViewController:dtvc animated:YES];
//depending on what button is tapped I want to send the number of the button pressed
}
가 어떻게이 수를 전송 할 수 있습니다 :
다음[cell.Btn1 addTarget:self action:@selector(BtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[cell.Btn2 addTarget:self action:@selector(BtnClicked:) forControlEvents:UIControlEventTouchUpInside];
은 방법 : 버튼을 누를 때
그때 나는이 전화를?편집
이 내 방법에서
내가
NSIndexPath *myIP = [NSIndexPath indexPathForRow:sender.tag inSection:0];
TwoMealsTableViewCell *cell = (TwoMealsTableViewCell*)[self.tableView cellForRowAtIndexPath:myIP];
무엇이 문제입니까? 귀하의 속성은 CellButton이 아닌 int에 입력해야합니다 (@property (비 원자) int 속성). 이 작업을 수행하기 위해 버튼을 서브 클래스 화해야한다는 것은 확실하지 않습니다. 버튼의 태그를 indexPath.row에 설정하고 있습니까? – rdelmar
@rdelmar 예 태그가 이미 사용되고 있습니다. 방금 내 셀의 단추에 속성을 추가하려고합니다. 그래서 내가 처음으로 btn을 눌렀거나 두 번째 버튼을 눌렀는지 알았습니다. 기본적으로 호출 된 메서드에서 어떤 단추를 눌렀는지 알고 싶습니다. –
원하는 경우 버튼의 제목을 확인하여이를 수행 할 수 있습니다. 그런 다음 버튼을 하위 클래스로 만들 필요가 없습니다. – rdelmar