Пользовательская ячейка, не подходящая для просмотра, вообще не выделяется - PullRequest
3 голосов
/ 05 ноября 2011

Я создал настраиваемую ячейку tableView и вижу свой tableView с нужной настраиваемой ячейкой.Теперь проблема в том, что я не могу выбрать строку таблицы.Я пытался отобразить вывод консоли изнутри - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath, но он никогда не вызывался.Я сбит с толку.Я не знаю, что я делаю не так.Ниже приведен мой индивидуальный класс ячейки:

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

}

Ниже приведена моя tableView: 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];
}

Любая помощь будет оценена.

Спасибо Вик

Ответы [ 3 ]

1 голос
/ 09 ноября 2011

Я понял.Я как-то имел self.tableView.allowsSelection = NO, и я пропустил этоТеперь работает нормально.Спасибо

0 голосов
/ 06 августа 2013

Привет, проверьте файлы XIB. перейдите в .xib, выберите свой вид и на правой панели проверьте «Взаимодействие с пользователем включено».

0 голосов
/ 05 ноября 2011

Попробуйте отменить выбор строки после вызова остальной части метода didSelectRowAtIndexPath.

Кроме того, вы объявили свой подкласс UITableViewController в качестве делегата табличного представления? Проще всего это сделать в IB. Если это не подкласс UITableViewController, вам нужно реализовать UITableViewDelegate самостоятельно, объявив его в заголовочном файле.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...