gpt4 book ai didi

ios - 单击按钮时在 tableViewCell 中配置数据

转载 作者:行者123 更新时间:2023-11-29 04:06:47 25 4
gpt4 key购买 nike

我正在使用 coreData 属性配置 UITableViewCell。我能够显示文本。但我想在单击按钮时使用其他数据重新加载单元格。

-(void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
Book *entity = [self.fetchedResultsController objectAtIndexPath:indexPath];
firstLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, 120, 21)];
secondLabel = [[UILabel alloc]initWithFrame:CGRectMake(120, 10, 120, 21)];

firstLabel.text = entity.title;
secondLabel.text = entity.author;

[cell.contentView addSubview:firstLabel];
[cell.contentView addSubview:secondLabel];

//On button Click i want to change firstLabel.text = entity.date and secondlabel.text = entity.details

}

最佳答案

试试这个代码..

设置全局变量

int buttonCliked;

设置按钮的操作

- (IBAction)aaaa:(id)sender
{
buttonCliked =1;
[_myTable reloadData];
}

用数据加载tableviewCell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

Book *entity = [self.fetchedResultsController objectAtIndexPath:indexPath];

firstLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, 120, 21)];
secondLabel = [[UILabel alloc]initWithFrame:CGRectMake(120, 10, 120, 21)];

if(!buttonClicked)
{
firstLabel.text = entity.title;
secondLabel.text = entity.author;
}
else
{
firstLabel.text = entity.date;
secondLabel.text = entity.details;

if(indexPath.row >= [tableView numberOfRowsInSection:indexPath.section] && indexPath.section >= [tableView numberOfSections])
{
buttonCliked =0;
}

}

[cell.contentView addSubview:firstLabel];
[cell.contentView addSubview:secondLabel];

return cell;


}

关于ios - 单击按钮时在 tableViewCell 中配置数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15066788/

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