단추가있는 사용자 지정 tableview 셀이 있습니다. 버튼을 클릭하면 tablview의 NSIndexPath 객체를 전달해야합니다. 나는 단추에 태그를 할당하고 발신자를 사용하여 태그를받습니다. 그러나 NSIndexPath 객체를 전달하려고합니다. 아래 코드가 있습니다.단추를 클릭 할 때 개체를 전달하는 방법
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"shortCodeCell";
IPadTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"KeywordsCell" owner:nil options:nil];
for (id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[IPadTableViewCell class]])
{
cell = (IPadTableViewCell *)currentObject;
}
}
}
// Delete
[cell.btnDelete addTarget:self action:@selector(onDelete:) forControlEvents:UIControlEventTouchUpInside];
cell.btnDelete.tag=indexPath.row;
return cell;
}
-(void)onDelete:(id)sender
{
UIButton *btn=(UIButton *)sender;
NSLog(@"BtnIndexpath to be deleted:%d",btn.tag);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
int errorCode = 0;
kd = [items objectAtIndex:btn.tag];
BOOL isDeleteKeyword= [ServerAPI deleteKeywordWithId:kd.keywordId :&errorCode];
dispatch_async (dispatch_get_main_queue(),
^{
if (isDeleteKeyword) {
[items removeObjectAtIndex:btn.tag];
//[tblKeywords deleteRowsAtIndexPaths:[NSArray arrayWithObject:btnIndexPath] withRowAnimation:YES];
[self.tblKeywords reloadData];
}
else return;
});
});
}
귀하의'tag'은'indexPath.row'에 같습니다. 'indexPath'에서 다른 어떤 정보를 원하십니까? – sunkehappy
아래의 onDelete 메소드에서 indexPath.row 인 정수 값이 아닌 indexPath 객체 만 전달하려고합니다. – user578386