Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 展开时如何隐藏展开的TableView标签国际标准化组织_Ios_Objective C_Uitableview_Expand - Fatal编程技术网

Ios 展开时如何隐藏展开的TableView标签国际标准化组织

Ios 展开时如何隐藏展开的TableView标签国际标准化组织,ios,objective-c,uitableview,expand,Ios,Objective C,Uitableview,Expand,我想在单元格展开时隐藏展开的TableView标签,在单元格折叠时隐藏按钮。我在另一个类中有我的单元格实现,在标题中有标签和按钮的属性。问题是,当我在ExpandedViewController中调用这些单元格方法时,代码会进入该方法,但不会更改属性行为。你能帮我解决这个问题吗 多谢各位 ExpandedCell.h @property (nonatomic, retain) IBOutlet UILabel *lblTitle; @property (strong, nonatomic) IB

我想在单元格展开时隐藏展开的TableView标签,在单元格折叠时隐藏按钮。我在另一个类中有我的单元格实现,在标题中有标签和按钮的属性。问题是,当我在ExpandedViewController中调用这些单元格方法时,代码会进入该方法,但不会更改属性行为。你能帮我解决这个问题吗

多谢各位

ExpandedCell.h

@property (nonatomic, retain) IBOutlet UILabel *lblTitle;
@property (strong, nonatomic) IBOutlet UIButton *setTime;
ExpandedCell.m

(void)setIfHidden:(BOOL)showIfHidden
{ 
if (showIfHidden)
{
[self.lblTitle setHidden:YES];
[self.setTime setHidden:NO];
}
else
{
[self.lblTitle setHidden:NO];
[self.setTime setHidden:YES];
}  
}
ExpandedViewController.m

import ExpandedCell.h


您的属性被标记为
IBOutlet
s。使用
[[ExpandedCell alloc]init]
创建单元格的新实例

您有几个问题:

  • 通过调用
    alloc init
    IBOutlet
    s将不存在,因为实例不是从NIB文件中未归档的
  • 一旦您创建了
    hideCell
    ,您就对它调用了一个方法,然后它就会被销毁(因为没有任何东西会保留它)
  • 您不应创建新单元格,而应访问和更新现有单元格,因此应使用:

  • 看看这个。
    (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    if ([indexPath isEqual:self.expandedIndexPath])
    {   
        return CELL_HEIGHT_EXPANDED;
    }
    else
    {
        return CELL_HEIGHT_COLLAPSED;
    }
    }
    (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    self.expandedIndexPath = ([self.expandedIndexPath isEqual:indexPath]) ? nil : indexPath;
    
    ExpandedCell *hideCell = [[ExpandedCell alloc] init];
    showIfHidden = YES;
    
    [hideCell setIfHidden:showIfHidden];
    
    [tableView beginUpdates];
    [tableView endUpdates];
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    }
    
    ExpandedCell *hideCell = [tableView cellForRowAtIndexPath:indexPath];