开发者

TalbeView cell showing null value

开发者 https://www.devze.com 2023-03-30 08:28 出处:网络
I have created a custom table for the rootViewController of a split view application so that the selected row expands and shows as a sub-table (showing main menu and sub menu ). The first row of the s

I have created a custom table for the rootViewController of a split view application so that the selected row expands and shows as a sub-table (showing main menu and sub menu ). The first row of the sub-table should show the particular main menu item of the sub-table.I'm fetching the main menu items from another class.

The problem is that the first row for the sub table is showing blank for me.Using NSLog, I checked the value of variable just before assigning it to the cell and even after assigning the value to the cell, i checked the text value in the cell using cell.textLabel.text. I'm getting the value in the console every time, but the row is still blank!!!

Row is showing the value if I'm hard coding it with any value!!!

Note:TableView is showing values for remaining rows.

Anybody can help me?? Thanks in advance...and sorry for my poor English..

EDIT: In the 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[开发者_Python百科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;
}

In the custom cell class (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

精彩评论

暂无评论...
验证码 换一张
取 消