2012-04-02 5 views
1

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

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

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

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

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

Сообщение код дружище .. –

+0

Вы реализовали метод - (Недействительными) Tableview: (UITableView *) Tableview didSelectRowAtIndexPath: (NSIndexPath *) indexPath Сообщает делегат, что чем выбранная строка теперь выбрана. –

ответ

3

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

[cell setSelectionStyle:UITableViewCellSelectionStyleBlue]; 

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

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


} 
3

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

cell.selectionStyle = UITableViewCellSelectionStyleNone; 

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

cell.selectionStyle = UITableViewCellSelectionStyleGray; 

или

cell.selectionStyle = UITableViewCellSelectionStyleBlue; 
Смежные вопросы