如何为另一个视图控制器页面传递结果字典的字典值

时间:2016-03-02 09:02:04

标签: ios objective-c

- (void)viewDidLoad 
{
  //json parsing 
    for (NSDictionary *ResultDictionary in dataDictionary) {
        ResultTabObject *ResultcurrenObjet = [[ResultTabObject alloc]initWithDate:[ResultDictionary objectForKey:@"MATCH_DATE"] ATeamName:[ResultDictionary objectForKey:@"COMPETITION_CODE"];
        [self.ResultHolderArray addObject:ResultcurrenObjet];
    }
}  
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{    
    static NSString *CellIdentifier = @"Cell";
    ResultTabCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    ResultTabObject *ResultcurrenObjet = [self.ResultHolderArray
                                 objectAtIndex:indexPath.row];
    cell.lblDate.text=ResultcurrenObjet.Date;
    return cell;
}
-(NSMutableArray *)ResultHolderArray{
    if(!_ResultHolderArray) _ResultHolderArray = [[NSMutableArray alloc]init];
    return _ResultHolderArray;
}

我通过使用上面的代码接收字典值现在我必须将ResultDictionary传递给另一个viewController 在此先感谢

1 个答案:

答案 0 :(得分:0)

嗯,有几种方法可以做到这一点,但一个简单的解决方案是在目标视图控制器上添加ResultDictionary属性,并在视图控制器更改之前进行设置。

你手动创建目标视图控制器然后就在那里。如果通过Interface Builder创建并连接视图控制器,则可以在- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender方法中设置属性,如下所示:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // You can use the segue identifier to make sure that you have the correct segue. If there is only one possible segue from your source view controller you can skip this step.
    if ([segue.identifier isEqualToString:@"your_segue_id"]) {
        DestinationViewController *vc = [segue destinationViewController];
        vc.resultTabObject = someResultTabObject; // get it from your array.
    }
}

PS:看看你的代码,我发现你可能意味着将ResultDictionary传递给单元格而不是实际的视图控制器。如果是这种情况,则只需在ResultDictionary类中添加ResultTabCell属性,并将其设置在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath内。