我有带有自定义单元格的 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
方法中,设置hide
为YES
,然后重新加载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/