Ios 如何从iAction方法更改自定义单元格的属性?

Ios 如何从iAction方法更改自定义单元格的属性?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有一个带有自定义单元格的表视图。 自定义单元格类具有以下属性: @property (nonatomic,retain ) IBOutlet ASStarRatingView *editableStarRatingView; - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { cell.editable

我有一个带有自定义单元格的表视图。

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

@property (nonatomic,retain ) IBOutlet ASStarRatingView *editableStarRatingView;
- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        cell.editableStarRatingView.canEdit = YES;
        cell.editableStarRatingView.maxRating = 5;
        cell.editableStarRatingView.rating=0;
        cell.editableStarRatingView.hidden = YES;
}
- (IBAction)AddRate:(id)sender {
    static NSString *CellIdentifier = @"Cell2";

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

}
CellForRowatineXpath方法有:

@property (nonatomic,retain ) IBOutlet ASStarRatingView *editableStarRatingView;
- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        cell.editableStarRatingView.canEdit = YES;
        cell.editableStarRatingView.maxRating = 5;
        cell.editableStarRatingView.rating=0;
        cell.editableStarRatingView.hidden = YES;
}
- (IBAction)AddRate:(id)sender {
    static NSString *CellIdentifier = @"Cell2";

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

}
然后是iAction方法:

@property (nonatomic,retain ) IBOutlet ASStarRatingView *editableStarRatingView;
- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        cell.editableStarRatingView.canEdit = YES;
        cell.editableStarRatingView.maxRating = 5;
        cell.editableStarRatingView.rating=0;
        cell.editableStarRatingView.hidden = YES;
}
- (IBAction)AddRate:(id)sender {
    static NSString *CellIdentifier = @"Cell2";

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

}

但EditableStaratingView仍然存在,并且没有隐藏

PlacesDetailsCell*单元格=[myTable dequeueReusableCellWithIdentifier:CellIdentifier];
这用于从池中获取重用单元格,而不是获取特定单元格。

隐藏所有
editablestartingview
在单元格中,尝试此操作

声明一个BOOL值,比如说它
BOOL-hide默认值为

-(iAction)AddRate:(id)sender
方法中,将
hide
设置为
YES
,然后重新加载tableview

- (IBAction)AddRate:(id)sender
{
    hide = !hide ;
    [myTable reloadData] ;
}
-(UITableViewCell*)表视图中:(UITableView*)表视图cellForRowAtIndexPath:(nsindepath*)indepath
,当hide为YES时,隐藏
editablestartingview

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

现在我知道你在找什么了。虽然你已经接受了答案,但我想发布这个答案,因为有更好的方法。不必重新加载整个表,该表将多次调用CellForRowatineXpath(基于可见单元格的数量),只需在隐藏视图后加载点击的单元格即可。请使用以下代码进行尝试:

- (IBAction)AddRate:(id)sender {
    CGPoint center = ((ASStarRatingView *)sender).center;
    CGPoint rootViewPoint = [sender.superview convertPoint:center toView:self.tableView];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:rootViewPoint];

    UITableViewCell *tapppedCell = [self.tableView cellForRowAtIndexPath:indexPath];
    tapppedCell.editableStarRatingView.hidden = YES;

    [self.tableView beginUpdates];
    [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
    [self.tableView endUpdates];

}

你能解释一下你想要什么吗?您想隐藏所有单元格中的
editablestartingview
还是只隐藏某个单元格中的某个单元格。@kudocc是的,单击某个按钮后,我想在所有单元格中隐藏editablestartingview!。谢谢你,你真是天才!,非常感谢。