gpt4 book ai didi

ios - 在 TableView 的原型(prototype)单元格中隐藏标签

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:25:02 24 4
gpt4 key购买 nike

我正在研究 Prototype TableView Cell,我在单元格上方有两个标签,在单元格后面有一个按钮。我想在“隐藏按钮”单击时隐藏第二个标签。我已经尝试了很多但没有得到任何合适的信息,这是我在单元格中显示标签的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *simpleTableIdentifier = @"TableCell";
TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

// Configure the cell...

int row = [indexPath row];
cell.EnglishLable.text = _English[row];
cell.UrduLable.text = _Urdu[row];
return cell;
}

一切都很好,我只需要在我的 Hide IBAction 方法中隐藏“UrduLabel”。

- (IBAction)Hide:(id)sender {



static NSString *simpleTableIdentifier = @"TableCell";
UITableView *tableView = [[UITableView alloc]init];
CGPoint location = [gestureRecognizer locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:IndexPath];
BOOL *hideLabel;
hideLabel = YES;
[self.tableView reloadData];
UILabel *subtitle = (UILabel *)[cell.contentView viewWithTag:1];
subtitle.hidden = hideLabel;
}

我的 Button 方法有什么问题?

最佳答案

试试这段代码

- (IBAction)Hide:(id)sender {

CGPoint location = [gestureRecognizer locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];

TableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.UrduLable.hidden = YES;
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:<any row animation you need>];

UILabel *subtitle = (UILabel *)[cell.contentView viewWithTag:1];
subtitle.hidden = hideLabel;

}

您只需要获取单击按钮的特定单元格,隐藏所需的标签并重新加载特定单元格。最主要的是你需要获取原型(prototype)单元类的实例,而不是 UITableViewCell

关于ios - 在 TableView 的原型(prototype)单元格中隐藏标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35313177/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com