Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何通过单击UITableViewCell发送数据';s按钮到另一个ViewController_Ios_Objective C_Json_Uitableview_Navigation - Fatal编程技术网

Ios 如何通过单击UITableViewCell发送数据';s按钮到另一个ViewController

Ios 如何通过单击UITableViewCell发送数据';s按钮到另一个ViewController,ios,objective-c,json,uitableview,navigation,Ios,Objective C,Json,Uitableview,Navigation,我想使用uitableviewcell中的按钮单击发送数据。我从web服务获取数据。每行按钮向viewController发送不同的数据。 将CellForRowatinex方法附加到下面: -(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath { static NSString *identifier = @"Category

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

-(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];
//}
}
请帮帮我
提前感谢

您需要使用
NSDictionary*dictReview=[\u arrsandelist objectAtIndex:sender.tag]-(void)showrating中单击:(UIButton*)sender
以获取适当的词典,然后在
dictMenuData
处使用它


从代码中完全删除
dictMenuData

您需要获取所选单元格按钮的索引。您可以从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
按钮被分配了一个标记,您可以在action方法中获取数据对象,与使用
indexpath.row
获取数据对象的方式相同

它的可能副本只发送tableviewIts的最后一个索引,因为您正在CellForRowAtIndexPath中重新填充数组,很高兴它有帮助。:)