모든 'btn1'은 같은 방법을 호출합니다.버튼이 눌린 행을 인식하십시오.
PS :이 내가 버튼을 누르면 한 행에서 얻을하는 방법을 알고 싶은 UITableView
입니다. 모든 버튼에서 루프를 만들려고했는데 버튼 태그가 마지막 태그와 다르게 설정되었습니다.
// Handle the buttons tag
int tagCount = 100;
// mainArray is the array of the tableView
for (int i = 0; i < [self.mainArray count]; i++) {
// I created a NSIndexPath to access the tableView cells
NSIndexPath *nowIndex = [NSIndexPath indexPathForRow:i inSection:0];
UITableViewCell *cell = (UITableViewCell *)[(UITableView *)self.view cellForRowAtIndexPath:nowIndex];
// I set the button tag as the 'int';
UIButton *shareButton = (UIButton *)[cell viewWithTag:100];
[shareButton setTag:tagCount];
tagCount++;
}
태그는 여전히 100과 같습니다.
모든 솔루션?
그게 내가 생각하기에 : 모든 행에서 루프를 수행하고 버튼 태그를'(마지막 행 태그) + 1'로 설정했지만 작동하지 않습니다. 방금 질문에 추가 한 코드를 살펴보십시오. –
tableView : cellForRowAtIndexPath 셀을 채우고 UIButton을 accessoryView로 설정할 때 해당 지점의 태그를 indexPath.row로 설정합니다. 모든 행에 대해 단일 UITableViewCell이 없습니다. UITableView는 화면에있는 것만을위한 충분한 셀을 생성합니다. 미리 (viewDidLoad의) 버튼을 만들거나 cellForRowAtIndexPath에 느리게 생성 할 수 있습니다. –
그건 좋은 생각이야. 'UIButton * shareButton = (UIButton *) [cell viewWithTag : 100]; [shareButton setTag : [indexPath row]]; ' –