无法选择单元格,但我可以设置textLabel

时间:2010-11-18 14:29:00

标签: iphone iphone-sdk-3.0 uitableview

我只想选择我的第一部分的第一个单元格,它的东西很简单,但它不想工作......

- (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变为“yes this changes”但是没有选择......

我尝试了不同的方法,重新加载后也是这样:

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

我不知道在哪里看...请帮忙

2 个答案:

答案 0 :(得分:0)

我不确定你想要做什么,但可能你应该尝试使用突出显示除了选择:

cell.selected = YES;
cell.highlighted = YES;

答案 1 :(得分: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];
}