【发布时间】:2018-08-20 10:52:37
【问题描述】:
我有一个表格视图,其中每一行都有一个按钮。我将数据存储为按钮的标题。
我需要什么:我想将所选按钮的标题传递给目标视图控制器。
代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSDictionary *dict = _json[indexPath.row]
[cell.bRedeem setTitle:dict[@"n_id"] forState:UIControlStateNormal];
}
- (IBAction)redeemClicked:(UIButton *)sender {
UIButton *button = (UIButton *)sender;
_nID = button.currentTitle;
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"showOffers"]) {
offerList *details = (offerList *)segue.destinationViewController;
details.nearID = _nID;
}
}
【问题讨论】:
-
你在哪里做 performSegue?
-
请参阅here 了解一系列解决方案。通常,您不应依赖单元格的内容,而应仅依赖其索引路径,然后您可以将其与数据源一起使用
标签: ios objective-c uitableview segue