objective-c - 如何将 tableview 单元格作为参数传递,并仅将图像加载到相应的 tableview 单元格(在 iOS 中单击照片按钮)

标签 objective-c ios xcode uitableview

我有一个自定义表格 View 。我想将表格 View 单元格作为参数传递给函数。我正在使用 [cell.btnImages PerformSelector]。单击照片按钮时,它应该将图像加载到相应的表格 View 单元格。这可能吗?下面是代码。单击图像按钮时。我需要将单元格作为参数传递... enter image description here

 - (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;

}

最佳答案

您已在 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

关于objective-c - 如何将 tableview 单元格作为参数传递,并仅将图像加载到相应的 tableview 单元格(在 iOS 中单击照片按钮),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13803802/

相关文章:

objective-c - tableview - 无法识别的选择器 didSelectRowAtIndexPath

iphone - 识别 UIImageView 区域中透明像素的百分比

iOS 选项卡栏项目自定义图像

ios - 在 iOS 中使用 Swift 消除 switch 语句中的重复

xcode - 如何创建带阴影的标签文本?

iphone - 关闭多个模态视图

objective-c - NSTimer 在滚动期间停止

iphone - 从没有框架的类添加 UIView

ios - 使用MuPDF从PDF提取文本时,文本的最后一行被截断

ios - 谷歌地图在标记信息窗口 iOS 中显示语音气泡