2010-11-18 4 views
0

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

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

    // Dequeue or create a cell of the appropriate type. 
    UITableViewCell *cell; 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    cell.accessoryType = UITableViewCellAccessoryNone; 
    cell.textLabel.font = [UIFont boldSystemFontOfSize:17]; 
    cell.selectionStyle = UITableViewCellSelectionStyleBlue; 


    switch (indexPath.section) { 
     case 0: 
     { 
      NSString *cellIconName = [[self subViewIconNames] objectAtIndex:[indexPath row]]; 
      UIImage *cellIcon = [UIImage imageNamed:cellIconName]; 
      [[cell imageView] setImage:cellIcon]; 
      cell.imageView.alpha = 0.5; 
      cell.textLabel.textColor = [UIColor grayColor]; 
      cell.textLabel.text = [self.subViewNames objectAtIndex:indexPath.row]; 


      if ([MyAppDelegate sharedAppDelegate].inSubView) { 
        cell.userInteractionEnabled = NO; 
       if (indexPath.row == 0) { 
        firstIndexPath =indexPath; 
        cell.selected = YES; 
        cell.textLabel.text = @"yes this changes"; 
       } 
      } 



      break; 
     } 
... 

поэтому изменений TextLabel в «да это меняется», но выбран не ...

Я пробовал разные подходы, и это после перезагрузки:

NSIndexPath *ip=[NSIndexPath indexPathForRow:0 inSection:0]; 
     [[MyAppDelegate sharedAppDelegate].rootViewController.tableView selectRowAtIndexPath:ip animated:YES scrollPosition:UITableViewScrollPositionBottom]; 

Я не знаю, где искать ... пожалуйста, помогите

ответ

0

Я не уверен, чтобы понять, что вы пытаетесь сделать, но может быть, вы должны попытаться использовать выделены в дополнение к отмеченными:

cell.selected = YES; 
cell.highlighted = YES; 
+0

Нет он все еще не выбран ... очень странно – meersmans

+0

Вы пытались использовать этот сеттер [cell setSelected: YES animated: YES]; ? – Romain

0

Попробуйте что-то вроде этого:

- (void) tableView:(UITableView *)tableView selectAndScrollToIndexPath:(NSIndexPath *)newSelectionIndexPath { 

    [tableView selectRowAtIndexPath:newSelectionIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; 
    [[tableView cellForRowAtIndexPath:newSelectionIndexPath] setSelected:YES animated:NO]; 

    [tableView scrollToRowAtIndexPath:newSelectionIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO]; 
} 
Смежные вопросы