0

カスタム テーブルビューを持っています。テーブルビュー セルをパラメータとして関数に渡したいです。[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 メソッドを実装するか、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 に答える