Xcode UITableView Строка не подсвечивается при выборе - PullRequest
1 голос
/ 02 апреля 2012

У меня в рабочем приложении для iphone есть рабочий стол, и я использую второе представление с помощью navigationController.

Но когда я пытаюсь выбрать ячейку на начальном экране, она не отвечает, т.е. не выделяется синим цветом, нет выделения.

Кто-нибудь может подсказать, что я мог упустить или что на самом деле отвечает за выбор ячейки, когда пользователь нажимает на нее?

ОК, спасибо за ваши предложения - все равно не повезло. вот мой код:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];

        [cell setSelectionStyle: UITableViewCellSelectionStyleBlue]; 

        UIView *selectionView = [[[UIView alloc] init] autorelease];
        selectionView.backgroundColor =[UIColor redColor];
        cell.selectedBackgroundView = selectionView;
    }

    // format text

    cell.textLabel.font = [UIFont fontWithName:@"Arial" size:12];
    cell.textLabel.text = [tableArray objectAtIndex:indexPath.row];

        return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    //NSUInteger row = indexPath.row;
    //[DetailView selectRowAtIndexPath:indexPath animated:YES];

    //UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath.row];
    //[cell setSelectionStyle: UITableViewCellSelectionStyleBlue]; 


    DetailView *detailView = [[DetailView alloc] initWithNibName:@"DetailView" bundle:nil];
    [self.navigationController pushViewController:detailView animated:YES];
    [DetailView release];

}

Ответы [ 2 ]

4 голосов
/ 02 апреля 2012

Может быть, вы сделали эту строку кода в cellForRowatIndexPath ::

 cell.selectionStyle = UITableViewCellSelectionStyleNone;

Если да, то замените его одним из следующих:

 cell.selectionStyle = UITableViewCellSelectionStyleGray;

или

 cell.selectionStyle = UITableViewCellSelectionStyleBlue;
3 голосов
/ 02 апреля 2012

Не глядя на ваш код, я бы сказал, что вы должны добавить эту строку в ваш cellForRowAtIndexPath метод делегата.

 [cell setSelectionStyle:UITableViewCellSelectionStyleBlue];

А также вы должны реализовать этот метод делегата, который вызывается при нажатии наячейка UITableView ..

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{


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