表格视图单元格显示空值

时间:2011-08-25 06:38:27

标签: iphone objective-c ipad uitableview

我为分割视图应用程序的rootViewController创建了一个自定义表,以便所选行展开并显示为子表(显示主菜单和子菜单)。子表的第一行应该显示子表的特定主菜单项。我从另一个类中获取主菜单项。

问题是子表的第一行显示为空白。使用NSLog,我在将变量赋值给单元格之前检查了变量的值,甚至在将值赋给单元格之后,我检查了文本使用cell.textLabel.text在单元格中的值。我每次都在控制台中获取值,但行仍然是空白的!

如果我使用任何值对其进行硬编码,则行显示该值!!!

注意:TableView显示剩余行的值。

任何人都可以帮助我?提前谢谢...抱歉我的英语很差..

编辑:在rootViewController

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    tableView.separatorColor=[UIColor grayColor];

    if (sectionopen[indexPath.row]) {
        accordianTable *cell1;
        cell1=(accordianTable *)[tableView dequeueReusableCellWithIdentifier:@"cell1"];

        if (cell1 == nil) {
            cell1 = [[[accordianTable alloc] initWithFrame:CGRectZero reuseIdentifier:@"cell1"] autorelease];
        }

        cell1.selectionStyle=UITableViewCellSelectionStyleNone;

        return cell1;
    } else {
    //tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    static NSString *CellIdentifier = @"CellIdentifier";

    // Dequeue or create a cell of the appropriate type.
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        cell.selectionStyle = UITableViewCellSelectionStyleGray;
    }
    // Configure the cell.
    cell.textLabel.text=[UIAppDelegate.mainMenu objectAtIndex:indexPath.row];

    return cell;
    }    
}

(void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    accordianTable *acc = [[accordianTable alloc]init];
    acc.titl=[UIAppDelegate.mainMenu objectAtIndex:indexPath.row];

    [acc.subTable reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
    ///turn them all off
    sectionopen[0]=NO;
    sectionopen[1]=NO;
    sectionopen[2]=NO;
    sectionopen[3]=NO;

    ///open this one
    sectionopen[indexPath.row]=YES;

    ///animate the opening and expand the row
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];

    UIViewController  *localdetailViewController = nil;
}

在自定义单元格类(accordianTable)中:

(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Number of rows is the number of time zones in the region for the specified section.
    return [UIAppDelegate.subMenu count]+1;//including title and sub menu
}

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *MyIdentifier = @"MyIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
    }

    switch (indexPath.row)
    {
        case 0:
            NSLog(@"text is   >>  %@",titl);
            cell.textLabel.text=titl;
            NSLog(@"text is   >>  %@",cell.textLabel.text);
            cell.textLabel.textColor=[UIColor whiteColor];
            cell.contentView.backgroundColor=[UIColor blackColor];
            cell.textLabel.backgroundColor=[UIColor blackColor];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            break;            
        default:
            int Row=indexPath.row;
            Row--;
            cell.textLabel.text=[UIAppDelegate.subMenu objectAtIndex:Row];
            cell.textLabel.textColor=[UIColor orangeColor];
            cell.textLabel.textAlignment=UITextAlignmentCenter;
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            break;
    }
    return cell;
}

0 个答案:

没有答案
相关问题