情况是这样的,我自定义了一个UITableViewCell,显示数据什么的都一切正常,但是单击cell的时候没有事件响应,didSelectRowAtIndexPath这个方法进不去,UITableViewDelegate, UITableViewDataSource必须的方法也已经实现了,头痛啊,求大虾指点~急死~
UITableViewCell的xib:
图传不上来了,大致情况就是3个label和两个imageview
实现类(网上的一个例子):#import "MessageTableCell.h"
@implementation MessageTableCell@synthesize imageView;
@synthesize nameLabel;
@synthesize decLabel;
@synthesize locLabel;
@synthesize helpImgeView;@synthesize image;
@synthesize helpImage;
@synthesize name;
@synthesize dec;
@synthesize loc;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        
    }
    return self;
}- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];    // Configure the view for the selected state
}- (void)setImage:(UIImage *)img {
    if (![img isEqual:image]) {
        image = [img copy];
        self.imageView.image = image;
    }
}-(void)setName:(NSString *)n {
    if (![n isEqualToString:name]) {
        name = [n copy];
        self.nameLabel.text = name;
    }
}-(void)setDec:(NSString *)d {
    if (![d isEqualToString:dec]) {
        dec = [d copy];
        self.decLabel.text = dec;
    }
}-(void)setLoc:(NSString *)l {
    if (![l isEqualToString:loc]) {
        loc = [l copy];
        self.locLabel.text = loc;
    }
}- (void)setHelpImage:(UIImage *)img {
    if (![img isEqual:helpImage]) {
        helpImage = [img copy];
        self.helpImgeView.image = helpImage;
    }
}@end在表视图中用这个MessageTableCell后,数据都正常,就是没法儿相应单击事件,求帮忙!

解决方案 »

  1.   

    didSelectRowAtIndexPath这个方法  响应的是tableview对象的委托方法,确认tableview.delegate = self;这句已加
      

  2.   

    tableview.delegate和tableview.dataSource都在IB关联过了,要不我把代码发给大虾给小弟瞧瞧?代码不复杂,就一小段测试代码
      

  3.   

    cell的.h文件#import <UIKit/UIKit.h>@interface MessageTableCell : UITableViewCell{
        IBOutlet UIImageView * imageView;
        IBOutlet UILabel * nameLabel;
        IBOutlet UILabel * decLabel;
        IBOutlet UILabel * locLabel;
        IBOutlet UIImageView *helpImgeView;
    }@property (nonatomic, retain) IBOutlet UIImageView * imageView;
    @property (nonatomic, retain) IBOutlet UILabel * nameLabel;
    @property (nonatomic, retain) IBOutlet UILabel * decLabel;
    @property (nonatomic, retain) IBOutlet UILabel * locLabel;
    @property (nonatomic, retain) IBOutlet UIImageView *helpImgeView;@property (copy, nonatomic) UIImage *image;
    @property (copy, nonatomic) UIImage *helpImage;
    @property (copy, nonatomic) NSString *name;
    @property (copy, nonatomic) NSString *dec;
    @property (copy, nonatomic) NSString *loc;@endcontroller的.h文件:#import <UIKit/UIKit.h>@interface LatestViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>@end
      

  4.   

    或者哪位大虾有可以响应的自定义cell的简单例子,可以让小弟瞧瞧,我对比下自己找原因。
      

  5.   

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 看看这个方法的实现。。
      

  6.   


    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *MyCellIdentifier = @"MyCellIdentifier";
        
        static BOOL nibsRegistered = NO;
        if (!nibsRegistered) {
            UINib *nib = [UINib nibWithNibName:@"MessageTableCell" bundle:nil];
            [tableView registerNib:nib forCellReuseIdentifier:MyCellIdentifier];
            nibsRegistered = YES;
        }
        
        MessageTableCell *cell = [tableView dequeueReusableCellWithIdentifier:MyCellIdentifier];
        if (cell == nil) { 
            cell = [[MessageTableCell alloc] 
                    initWithStyle:UITableViewCellStyleDefault 
                    reuseIdentifier:MyCellIdentifier]; 
        }
        
        NSUInteger row = [indexPath row];
        
        cell.name = [dataList objectAtIndex:row];//datalist是一些假数据
        cell.dec = [dataList objectAtIndex:row];
        cell.loc = [dataList objectAtIndex:row];
        cell.image = [imageList objectAtIndex:row];
        cell.helpImage = [UIImage imageNamed:@"chat_message.png"];
        [cell setUserInteractionEnabled:YES];
        
        return cell;
    }
      

  7.   

    应该是XIB文件设置的问题。
    你可以试试代码关联的方式。
    例子:http://code4app.com/ios/%E7%AE%80%E5%8D%95UITableViewDemo/505548916803fa6b06000000
      

  8.   

    为了保险期间最好还是手动设置代理引用
    self.tableView.delegate=self;
    self.tableView.datasource=self;如果都设置好,一般是能访问到didSelectedRowAtIndex: 协议方法的。还是检查一下,这种可能性要大一些。还有就是在UITableViewCell的- (void)setSelected:(BOOL)selected animated:(BOOL)animated 方法也可以响应点击事件。
      

  9.   


    谢谢各位啦,我找到根源了,- (NSIndexPath *)tableView:(UITableView *)tableView 
      willSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
        return nil;
    }因为这个方法,刚学这些方法都不熟悉,刚才删掉了这个方法就可以了,然后到开发手册查了下这个方法,有这么一句话:
    Return Value
    An index-path object that confirms or alters the selected row. Return an NSIndexPath object other than indexPath if you want another cell to be selected. Return nil if you don'€™t want the row selected.
    是nil的原因,好坑爹啊,新手真的伤不起
      

  10.   

    楼主 在tableview里面加了这个方法以后我还是不能通过点击cell 跳转,是为什么呢
      

  11.   

    我看的自定义cell教程和你一样的- -