我想在https://github.com/singhson/Expandable-Collapsable-TableView上做一个使用故事板的例子。我正在尝试使用xib文件来做到这一点。我应该在cellForRowAtIndexPath中做什么修改,以便我可以得到所需的输出结果?我想是这样的名称不显示在UITableView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *[email protected]"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if(cell==nil)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
NSString *Title= [[self.itemsInTable objectAtIndex:indexPath.row] valueForKey:@"Name"];
[self createCellWithTitle:Title image:[[self.itemsInTable objectAtIndex:indexPath.row] valueForKey:@"Image name" ] indexPath:indexPath];
// return [self createCellWithTitle:Title image:[[self.itemsInTable objectAtIndex:indexPath.row] valueForKey:@"Image name"] indexPath:indexPath];
return cell;
}
- (UITableViewCell*)createCellWithTitle:(NSString *)title image:(UIImage *)image indexPath:(NSIndexPath*)indexPath
{
NSString *CellIdentifier = @"Cell";
ExpandableTableViewCell* cell = [self.menuTableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIView *bgView = [[UIView alloc] init];
bgView.backgroundColor = [UIColor grayColor];
cell.selectedBackgroundView = bgView;
cell.lblTitle.text = title;
cell.lblTitle.textColor = [UIColor blackColor];
[cell setIndentationLevel:[[[self.itemsInTable objectAtIndex:indexPath.row] valueForKey:@"level"] intValue]];
cell.indentationWidth = 25;
float indentPoints = cell.indentationLevel * cell.indentationWidth;
cell.contentView.frame = CGRectMake(indentPoints,cell.contentView.frame.origin.y,cell.contentView.frame.size.width - indentPoints,cell.contentView.frame.size.height);
NSDictionary *d1=[self.itemsInTable objectAtIndex:indexPath.row] ;
if([d1 valueForKey:@"SubItems"])
{
cell.btnExpand.alpha = 1.0;
[cell.btnExpand addTarget:self action:@selector(showSubItems:) forControlEvents:UIControlEventTouchUpInside];
}
else
{
cell.btnExpand.alpha = 0.0;
}
return cell;
}
现在我得到它可以展开或折叠表,但我不显示表视图名称。我应该做些什么改变才能发挥作用?请帮忙。
你可以显示方法:'createCellWithTitle'? –
此外,NSString *标题不应该以大写开头 –
检查我更新的代码 – Itaws