ios - 如何从 IBAction 方法更改自定义单元格的属性?

标签 ios objective-c uitableview

我有带有自定义单元格的 TableView 。

自定义单元类具有以下属性:

@property (nonatomic,retain ) IBOutlet ASStarRatingView *editableStarRatingView;

cellforRowAtindexPath 方法有:

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        cell.editableStarRatingView.canEdit = YES;
        cell.editableStarRatingView.maxRating = 5;
        cell.editableStarRatingView.rating=0;
        cell.editableStarRatingView.hidden = YES;
}

然后是 IBAction 方法:

- (IBAction)AddRate:(id)sender {
    static NSString *CellIdentifier = @"Cell2";

    PlacesDetailsCell *cell = [myTable dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.editableStarRatingView.hidden=YES;

}

但是 editableStarRatingView 仍然存在并且没有隐藏!

最佳答案

隐藏单元格中的所有 editableStarRatingView,试试这个。

声明一个 BOOL 值,假设它是 BOOL hide;,默认值为 NO

- (IBAction)AddRate:(id)sender方法中,设置hideYES,然后重新加载tableview。

- (IBAction)AddRate:(id)sender
{
    hide = !hide ;
    [myTable reloadData] ;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 中,当 hide 为 YES 时隐藏 editableStarRatingView

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.editableStarRatingView.canEdit = YES;
    cell.editableStarRatingView.maxRating = 5;
    cell.editableStarRatingView.rating=0;
    cell.editableStarRatingView.hidden = hide ;
}

关于ios - 如何从 IBAction 方法更改自定义单元格的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21360507/

相关文章:

ios - 如何获取 iBeacon 的坐标?

objective-c - iOS - Facebook 连接注销不删除登录详细信息?

objective-c - xCode 4.4 没有获取所有 .pch 文件头导入?

ios - 以编程方式重新排序 subview 在 tableViewCell 中不起作用

ios - 按日期和字符对核心数据属性进行排序

ios - 隐藏自定义工具栏按钮

ios - 如何在 iOS-Charts 中显示重新加载文本?

iphone - UIScrollView 未检测到折叠后的触摸

ios - UITableView onItemSelect 内的 Swift UICollectionView

ios - 以编程方式添加到 View Controller 的 UITableView 不会填充