gpt4 book ai didi

ios - 如何将数据放入自定义单元格中的按钮?

转载 作者:行者123 更新时间:2023-11-29 01:24:43 25 4
gpt4 key购买 nike

我有一个名为 custom cell(.h .m) 的类,它在我想存储数据的按钮中创建了 4 个按钮?该数据来自 JSON 解析器。这是我的代码

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellId = @"Cell";
ContestQATableViewCell *cell = (ContestQATableViewCell *)[tableViewQA dequeueReusableCellWithIdentifier:cellId];
if (cell==nil)
{
NSArray *myNib;
myNib =[[NSBundle mainBundle]loadNibNamed:@"ContestQATableViewCell" owner:self options:nil];
cell = (ContestQATableViewCell *)[myNib lastObject];
}
NSString *str = [getAnswer1Array objectAtIndex:indexPath.row];
NSLog(@"%@",str);
cell.question.text = [getContestQArray objectAtIndex:indexPath.row];
[UIButton setTitle:cell.answer1 forState:UIControlStateNormal];
[UIButton setTitle:cell.answer2.userActivity forState:UIControlStateNormal];
[UIButton setTitle:cell.answer3. forState:UIControlStateNormal];
}

最佳答案

按照以下步骤操作

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *customTableIdentifier=@"CustomCell";
ContestQATableViewCell *cell=(ContestQATableViewCell*)[tableView dequeueReusableCellWithIdentifier:customTableIdentifier];
if (cell==nil)
{
NSArray *nibs=[[NSBundle mainBundle]loadNibNamed:@"CustomCell" owner:self options:nil];
cell=[nibs objectAtIndex:0];
}
cell.btnFirst.titleLabel.text = [NSString stringWithFormat:@"%@",[getContestQArray objectAtIndex:indexPath.row]];

cell.btnSecond.titleLabel.text = [NSString stringWithFormat:@"%@",[getSecondArray objectAtIndex:indexPath.row]];

cell.btnThird.titleLabel.text = [NSString stringWithFormat:@"%@",[getThirdArray objectAtIndex:indexPath.row]];

cell.btnFourth.titleLabel.text = [NSString stringWithFormat:@"%@",[getFourthArray objectAtIndex:indexPath.row]];

return cell;
}

关于ios - 如何将数据放入自定义单元格中的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34153368/

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