0

カスタム セルがあり、このカスタム セルにはボタンとラベルがあります。

#import <UIKit/UIKit.h>

@interface ListCell : UITableViewCell{

}
@property (nonatomic, retain) IBOutlet UIButton* buttonContent;
@property (nonatomic, retain) IBOutlet UILabel* detailContent;

@end

ボタンのクリックイベントを処理するとき:

- (IBAction)expandListCell:(id)sender{
    UIButton *button = (UIButton *)sender;
    ListCell *cell = (ListCell *)button.superview;
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
    cell.detailContent.text = @"FALSE"; // It throw an exception   
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"listCell";
    ListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];   
    cell.buttonContent.tag = indexPath.row;
    return cell;
}

カスタム セル (ListCell) からアイテムにアクセスしようとすると、例外がスローされます。

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCellContentView detailContent]: unrecognized selector sent to instance 0x8887ca0'

カスタムセルの入手方法が間違っていると思います。正しい入手方法を知っている人はいますか?
少し早いですがお礼を

4

2 に答える 2

4

あなたは正しいクラスを呼んでいますか?ボタンのスーパー ビュー クラスは ListCell クラスですか?

これを確認してみてください:

    // (...)
    ListCell *cell = (ListCell *)button.superview;
    if ([cell.class isSubclassOfClass:[ListCell class]]) {
        ///// just a check for indexPath: /////
        NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
        NSLog(@"current indexPath: %@", indexPath );
        ///////////// END CHECK ///////////////
        cell.detailContent.text = @"FALSE"; 
    }else{
        NSLog(@"NOT THE RIGHT CLASS!!!");
    }
于 2012-04-13T09:55:10.767 に答える
1

わかりました。質問を適切に取得できなかったことをお詫びします。セルに追加する前にラベル ビューに teg を割り当ててから、取得時に使用するだけです。

UILabel *name = (UILabel *)[cell viewWithTag:kLabelTag];

ラベルのテキストを設定します

于 2012-04-13T09:54:10.780 に答える