0

我有一个自定义表格视图。我想将表格视图单元格作为 pramater 传递给一个函数。我正在使用 [cell.btnImages performSelector]。单击照片按钮时,它应该将图像加载到相应的表格视图单元格中。是否可能?下面是代码。单击图像按钮时。我需要将单元格作为参数传递... 在此处输入图像描述

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"IpadTableViewCell";

IPadTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"IpadTableViewCell" owner:nil options:nil];
    for (id currentObject in topLevelObjects)
    {
        if ([currentObject isKindOfClass:[IPadTableViewCell class]])
        {
            cell = (IPadTableViewCell  *)currentObject;

        }
    }
}

  [cell.btnImages performSelector:@selector(imageButtonClicked:) onThread:nil withObject:cell waitUntilDone:nil];


return cell;
}



-(void)imageButtonClicked:(IPadTableViewCell *)tblCell
 {
// opne image select dialog
CGFloat prevButtonXPosition = 17, pageButtonXPosition, pageButtonWidth = 120, pageButtonHeight = 130;

   for (NSInteger i =1; i<= 9; i++) {
    pageButtonXPosition = prevButtonXPosition ;
    prevButtonXPosition = pageButtonXPosition + pageButtonWidth;
    UIButton *pageButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [pageButton addTarget:self action:@selector(onClickImage:) forControlEvents:UIControlEventTouchUpInside];
    [pageButton setFrame:CGRectMake(pageButtonXPosition, 5, pageButtonWidth, pageButtonHeight)];
    [pageButton setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%i.png",i]] forState:UIControlStateNormal];
    [pageButton setTag:i];
    [cell.scrollView addSubview:pageButton];
}

UIButton *add=[UIButton buttonWithType:UIButtonTypeCustom];
[add addTarget:self action:@selector(onClickAdd:) forControlEvents:UIControlEventTouchUpInside];
[add setFrame:CGRectMake(prevButtonXPosition, 20, 80, 80)];
[add setBackgroundImage:[UIImage imageNamed:@"last.jpeg"] forState:UIControlStateNormal];
[add setTag:0];
[cell.scrollView addSubview:add];

[cell.scrollView setContentSize:CGSizeMake(prevButtonXPosition +80, 40)];
cell.selectionStyle = UITableViewCellSelectionStyleNone;

}
4

1 回答 1

1

您已经在 tableview 类中定义了 imageButtonClicked 方法,但您在 cell.btnImages 中调用它。您应该在 btnImages 类中实现 imageButtonClicked 方法,或者在 self 而不是 cell.btnImages 中调用它。如果 btnImages 属于 UIButton 类,您应该这样做:

[cell.btnImages addTarget:self action:@selector(imageButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

或者干脆实现 UITableViewDelegate 方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
于 2012-12-11T09:11:36.000 回答