Ios 如何通过单击UITableViewCell发送数据';s按钮到另一个ViewController
我想使用uitableviewcell中的按钮单击发送数据。我从web服务获取数据。每行按钮向viewController发送不同的数据。 将CellForRowatinex方法附加到下面: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 *) 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中重新填充数组,很高兴它有帮助。:)