将Json数据传递给另一个ViewController表按钮单击

时间:2015-03-26 11:28:04

标签: ios json uitableview storyboard cell

我正在开发一个ios应用程序。在按钮上单击Json数据以传递另一个ViewController ...但是TableView不显示Json Data..TableView显示为空

 BBAdsViewController *BBAuthorDetail =[[UIStoryboard storyboardWithName:@"Main" bundle:nil]instantiateViewControllerWithIdentifier:@"AdsViewController"];

        [BBAuthorDetail setDelegate:self];
        [BBAuthorDetail setSelectionType:BBSelectionAuthorName];
        _serverObj = [[Server alloc]init];
        [_params setObject:_adDetailsObj.authorDetail forKey:@"author"];
        [_serverObj BBAuthorNameWithParams:_params];
     [BBAuthorDetail setManagedObjectContext:self.managedObjectContext];
    [self.navigationController pushViewController:BBAuthorDetail animated:YES];


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellIdentifier = [NSString stringWithFormat:@"Cell-%li", (long)indexPath.row];
    BBAdsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];


    Ad *adObj = (Ad *)[self.adsFilteredArray objectAtIndex:indexPath.row];

    if (cell == nil) {
        cell = [[BBAdsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.row = indexPath.row;
        [cell setDelegate:self];
    }

    if (![adObj.gallery isEqual:[NSNull null]]) {
        NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:adObj.gallery]];
        [cell.adImageView setImageWithURLRequest:imageRequest placeholderImage:[UIImage imageNamed:@"ship_placeholder.png"] success:nil failure:nil];
    }
    else
    {
        [cell.adImageView setImage:[UIImage imageNamed:@"ship_placeholder.png"]];
    }
    if (_serverCallType == ServerCallTypeAdvancedSearch || _serverCallType == ServerCallTypeSearch ) {
        [cell.phoneButton setHidden:NO];
        [cell.categoryLabel setHidden:YES];
        [cell.authorLabel setHidden:YES];
        [cell.addressLabel setHidden:YES];
        [cell.favButton setCenter:CGPointMake(CGRectGetMaxX(cell.phoneButton.frame) + 25.0f, CGRectGetMidY(cell.phoneButton.frame))];
    }    else
    {
        [cell.phoneButton setHidden:YES];
        [cell.favButton setCenter:CGPointMake(CGRectGetWidth(cell.frame) - 30.0f, 65.0f)];
    }

    if (_selectionType == BBSelectionBoat || _selectionType == BBSelectionOtherBoat || _selectionType == BBlatestBoat )
    {
        if (adObj.price && ![adObj.price isEqualToString:@""]) {
            [cell.priceLabel setHidden:NO];
            [cell.priceLabel setText:adObj.price];
        }
        [cell.categoryLabel setCenter:CGPointMake(CGRectGetMidX(cell.authorLabel.frame), CGRectGetMinY(cell.authorLabel.frame) - 7.0f)];

        if (_serverCallType == ServerCallTypeAdvancedSearch || _serverCallType == ServerCallTypeSearch)
        {
            [cell.authorLabel setHidden:YES];
            [cell.addressLabel setHidden:YES];

        }

        else
        {
            cell.authorLabel.text = adObj.authorName;
            cell.addressLabel.text = adObj.address;
            [cell.authorLabel setHidden:YES];
            [cell.addressLabel setHidden:NO];
        }
    }
    else
    {
        [cell.priceLabel setHidden:YES];
        [cell.authorLabel setHidden:YES];
        [cell.addressLabel setHidden:YES];

        [cell.categoryLabel setCenter:CGPointMake(CGRectGetMidX(cell.addressLabel.frame), CGRectGetMidY(cell.addressLabel.frame))];
    }

    [cell.favButton setSelected:adObj.isFavorite];
    NSRange range = [adObj.title rangeOfString:@","];
    cell.titleLabel.text = range.location == NSNotFound ? adObj.title : [adObj.title substringToIndex:range.location];
    [cell.titleLabel setNumberOfLines:0];
    cell.categoryLabel.text = adObj.category;
    return  cell;
}

1 个答案:

答案 0 :(得分:0)

下面是将数据从一个视图控制器传递到另一个视图控制器的简单示例。

//FirstViewController.m

//on button click

SecondViewController *secondViewContrler = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];


secondViewContrler.dataArray = dataArrayWithData; //assign value



//SecondViewController.h

@property (retain , nonatomic) NSMutableArray* dataArray;

//SecondViewController.m
@synthesize dataArray;