Iphone TalbeView单元格显示空值
我已经为拆分视图应用程序的Iphone TalbeView单元格显示空值,iphone,objective-c,ipad,uitableview,Iphone,Objective C,Ipad,Uitableview,我已经为拆分视图应用程序的rootViewController创建了一个自定义表,以便所选行展开并显示为子表(显示主菜单和子菜单)。子表的第一行应该显示子表的特定主菜单项。我正在从另一个类获取主菜单项 问题是子表的第一行显示为空。在将变量赋值给单元格之前,我使用NSLog检查了变量的值,甚至在将值赋值给单元格之后,我也使用cell.textlab.text检查了单元格中的文本值。我每次都会在控制台中获取值,但行仍然为空 如果我用任何值对行进行硬编码,行将显示值 注意:TableView显示剩余行
rootViewController
创建了一个自定义表,以便所选行展开并显示为子表(显示主菜单和子菜单)。子表的第一行应该显示子表的特定主菜单项。我正在从另一个类获取主菜单项
问题是子表的第一行显示为空。在将变量赋值给单元格之前,我使用NSLog检查了变量的值,甚至在将值赋值给单元格之后,我也使用cell.textlab.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;
}
在自定义单元类(一致性)中:
你能给这个问题加一点代码吗?这将对那些想回答你的问题的人非常有帮助。@Nithin:谢谢你的回答。我用一些代码编辑了这个问题。
(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;
}