Ios5 未选择Uitable view自定义单元格

Ios5 未选择Uitable view自定义单元格,ios5,uitableview,Ios5,Uitableview,我创建了一个自定义的tableView单元格,可以看到带有所需自定义单元格的tableView。现在的问题是我无法选择我的表行。我试图在-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(nsindepath*)indepath中显示控制台输出 但它从来没有打过电话。我很困惑。我不知道我做错了什么。以下是我的自定义单元格类: - (id)initWithFrame:(CGRect)frame reuseIdentif

我创建了一个自定义的tableView单元格,可以看到带有所需自定义单元格的tableView。现在的问题是我无法选择我的表行。我试图在
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(nsindepath*)indepath中显示控制台输出
但它从来没有打过电话。我很困惑。我不知道我做错了什么。以下是我的自定义单元格类:

- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {

    if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {

        // Initialization code

        CGRect contentRect = self.contentView.bounds;
        CGFloat boundsX = contentRect.origin.x;

        _title = [[UILabel alloc]initWithFrame:CGRectMake(boundsX +70, 5, 100, 25)];
        _title.textAlignment = UITextAlignmentLeft;
        _title.font = [UIFont systemFontOfSize:14];

        _details = [[UILabel alloc]initWithFrame:CGRectMake(boundsX + 70, 30, 100, 15)];
        _details.textAlignment = UITextAlignmentLeft;
        _details.font = [UIFont systemFontOfSize:10];

        _duration = [[UILabel alloc] initWithFrame:CGRectMake(boundsX + 200, 10, 65, 15)];
        _duration.textAlignment = UITextAlignmentRight;
        _duration.font = [UIFont systemFontOfSize:10];

        _price = [[UILabel alloc]initWithFrame:CGRectMake(boundsX + 180, 30, 80, 15)];
        _price.textAlignment = UITextAlignmentRight;
        _price.font = [UIFont systemFontOfSize:10];

        _listingImage = [[UIImageView alloc]initWithFrame:CGRectMake(boundsX +10, 0, 50, 50)];

        [self.contentView addSubview:_title];
        [self.contentView addSubview:_details];
        [self.contentView addSubview:_price];
        [self.contentView addSubview:_duration];
        [self.contentView addSubview:_listingImage];

        [_title release];
        [_details release];
        [_duration release];
        [_price release];
        [_listingImage release];

    }

    return self;

}
下面是我的
表格视图:cellForRowAtIndexPath:
函数:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";


    CustomizedCell *cell = (CustomizedCell *) [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[[CustomizedCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
     //   cell = [[[CustomizedCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];

    }

    ADJListing *listing = [self.dataSource.listings objectAtIndex:indexPath.row];

    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;


    cell._title.text = listing.title;
    cell._details.text = listing.details;
    cell._price.text = [listing.price stringValue];
    cell._duration.text = (NSString*) listing.start_datetime;
    cell._listingImage.image = [UIImage imageNamed:@"picture.png"];

    return cell;
}
这也是我的
tableView:didSelectRowAtIndexPath:
方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   // [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSLog(@"data");

    detailedVC = [[DetailedViewController alloc] init];
    detailedVC.dataSource = self.dataSource;
    [self.navigationController pushViewController:detailedVC animated:YES];
    [detailedVC release];
}
任何帮助都将不胜感激

谢谢
Vik

在调用didSelectRowAtIndexPath方法的其余部分后,尝试取消选择该行


另外,您是否已将UITableViewController子类声明为tableview的委托?在IB中执行此操作最简单。如果这不是UITableViewController子类,则需要通过在头文件中声明来实现UITableViewDelegate。

我知道了。不知怎的,我有self.tableView.allowssection=NO,但我错过了它。现在工作正常了。谢谢

您好,请查看xib文件。
转到.xib,选择您的视图,并在右侧面板中检查“已启用用户交互”。

Hi W Dyson。谢谢你的回复。我也试过了。但是没有变化。它也是一个UIViewController子类,我已经在头文件中声明了UITableViewDelegate,并且我已经将tableView的委托设置为self.Hi。我得到了它。不知怎的,我有self.tableView.allowssection=NO,但我错过了它。现在工作正常了。谢谢你,小鸟,我也有同样的问题。在玩了一点XIB文件之后,我必须显式地设置这个属性,即使很难,它也是默认的!