我有這樣的cellForRowAtIndexPath方法在這裏:Objective-C的傳遞的tableView indexPath另一個方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
if (cell.accessoryView == nil) {
cell.accessoryView = [[Checkbox alloc] initWithFrame:CGRectMake(0, 0, 25, 43)];
cell.accessoryView.opaque = NO;
cell.backgroundColor = [UIColor clearColor];
[(Checkbox*)cell.accessoryView addTarget:self action:@selector(checkBoxTapped:forEvent:) forControlEvents:UIControlEventValueChanged];
}
NSString *sectionTitle = [contactSectionTitles objectAtIndex:indexPath.section];
NSArray *sectionContacts = [contactDirectoryFinal objectForKey:sectionTitle];
NSString *contacts = [[sectionContacts objectAtIndex:indexPath.row] valueForKey:@"item"];
cell.textLabel.text = contacts;
[(Checkbox*)cell.accessoryView setChecked: [[[sectionContacts objectAtIndex:indexPath.row] valueForKey:@"checkedItem"] boolValue] ];
return cell;
}
這個方法裏面,我有這樣一行:
[(Checkbox*)cell.accessoryView addTarget:self action:@selector(checkBoxTapped:forEvent:) forControlEvents:UIControlEventValueChanged];
調用該方法
- (IBAction)checkBoxTapped:(id)sender forEvent:(UIEvent*)event
{
}
我想要做的是調整這個方法的調用方式,所以我也通過int indexPath.row數
我開始了這一點:
[(Checkbox*)cell.accessoryView addTarget:self action:@selector(checkBoxTapped:forEvent:rowNumber:) forControlEvents:UIControlEventValueChanged];
這
- (IBAction)checkBoxTapped:(id)sender forEvent:(UIEvent*)event rowNumber:(int)row
{
}
,但我是新來的選擇,我的問題是我在哪裏傳中ROWNUMBER?
訪問的
UITableViewCell
對象您是否嘗試過使用'accessoryButtonTappedForRowWithIndexPath :(NSIndexPath *)indexPath'? – CaptJak