gpt4 book ai didi

ios - 如何通过单击 UITableViewCell 按钮将数据发送到另一个 ViewController

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:30:13 26 4
gpt4 key购买 nike

我想使用 uitableviewcell 中的按钮单击发送数据。我从网络服务中获取数据。每行按钮向 viewController 发送不同的数据。 在下面附加 cellForRowAtIndex 方法:

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

static NSString *identifier = @"CategoryCell";
NSDictionary *dictMenuData = [_arrHandMadeList objectAtIndex:indexPath.row];
CategoryCell *cell = (CategoryCell *)[tableView dequeueReusableCellWithIdentifier:identifier];

if(!cell) {
[tableView registerNib:[UINib nibWithNibName:@"CategoryCell" bundle:nil] forCellReuseIdentifier:identifier];
cell = (CategoryCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
}

cell.btnShowRatingDetails.tag = indexPath.row;
[cell.btnShowRatingDetails addTarget:self action:@selector(showRatingClicked:) forControlEvents:UIControlEventTouchUpInside];

[arrReview removeAllObjects];
//arrReview = [dictMenuData objectForKey:@"RivewData"];
[arrReview addObjectsFromArray:[dictMenuData objectForKey:@"RivewData"]];

[cell setupHandMadeCell:dictMenuData];

return cell;
}

按钮的方法如下:

-(void) showRatingClicked:(UIButton*)sender {

//if (sender.tag == currentIndex) {
ReviewVC *rvc = (ReviewVC*)[self.storyboard instantiateViewControllerWithIdentifier:@"ReviewVC"];

rvc.arrReviewDetails = arrReview;
rvc.strRestaurentName = [dictMenuData objectForKey:@"Restaurant_Name"];
rvc.strRestaurentId = [dictMenuData objectForKey:@"Restaurant_Id"];
rvc.strRestaurentRating = [dictMenuData objectForKey:@"Stars"];

[self.navigationController pushViewController:rvc animated:YES];
//}
}

请帮帮我提前致谢

最佳答案

您需要获取所选单元格按钮的索引。您可以从 sender.tag 中获取它。

-(void) showRatingClicked:(UIButton*)sender {

ReviewVC *rvc = (ReviewVC*)[self.storyboard instantiateViewControllerWithIdentifier:@"ReviewVC"];

NSDictionary *dictMenuData = [_arrHandMadeList objectAtIndex:sender.tag];

rvc.arrReviewDetails = [dictMenuData objectForKey:@"RivewData"]; //or as per your data
rvc.strRestaurentName = [dictMenuData objectForKey:@"Restaurant_Name"];
rvc.strRestaurentId = [dictMenuData objectForKey:@"Restaurant_Id"];
rvc.strRestaurentRating = [dictMenuData objectForKey:@"Stars"];

[self.navigationController pushViewController:rvc animated:YES];

}

一旦为 cell.btnShowRatingDetails.tag = indexPath.row; 按钮分配了标签,您就可以在操作方法中获取数据对象,与使用 indexpath.row< 获取数据对象的方式相同

关于ios - 如何通过单击 UITableViewCell 按钮将数据发送到另一个 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48921873/

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