需要 iOS :d ata 通信帮助



我正在遵循MVC模式进行数据通信,我不知道到底发生了什么问题。需要解决这个问题。场景是:
我有一类列表项目,即:模型


#import "Listing_Ads.h"
@implementation Listing_Ads

#pragma mark -
#pragma mark Properties Synthesized
@synthesize     item_id         =   _item_id;
@synthesize     title_value     =   _title_value;
@synthesize     desc_value      =   _desc_value;
@synthesize     kategory        =   _kategory;
@synthesize     imagesAtIndex   =   _imagesAtIndex;
@synthesize     reviews         =   _reviews;

#pragma mark -
#pragma mark Data_Allocation
- (id)initWithDictionary:(NSDictionary *)dictionary
{
    self = [super init];
    if (self)
    {
        self.item_id            =   [dictionary valueForKey:@"id"];
        self.title_value        =   [dictionary  valueForKey:@"title"];
        self.desc_value         =   [dictionary  valueForKey:@"description"];
        if ([[dictionary valueForKey:@"my_images"] isKindOfClass:[NSNull class]])
        {
            self.image          =  @"";
        }
        else
        {
            NSString * rawImages;
            rawImages           = [dictionary valueForKey:@"my_images"];
            self.imagesAtIndex  = [rawImages componentsSeparatedByString:@","];
            self.image          =   self.imagesAtIndex[0];
        }
            self.kategory       =   [dictionary  valueForKey:@"category"];
    }
            self.reviews        =   [dictionary valueForKey:@"reviews"];
    return self;
}
-(NSDictionary*)details_Listing
{
    NSDictionary * detailsDictionary= [NSDictionary dictionary];

    [detailsDictionary setValue:self.item_id forKey:@"itemID"];
    [detailsDictionary setValue:self.title_value forKey:@"title"];
    [detailsDictionary setValue:self.desc_value forKey:@"description"];
    [detailsDictionary setValue:self.imagesAtIndex forKey:@"images"];

    NSLog(@"details of product are here:%@",detailsDictionary);
    return detailsDictionary;
}


我正在第一个视图控制器中发出请求并获取正在显示的所有结果。 但我无法将值传递给详细视图控制器
在FirstVC.h

@property (nonatomic, retain) NSMutableArray * ads_Array;

在FirstVC.m

[manager GET:self.urlString parameters:nil progress:nil success:^(NSURLSessionTask * task, id responseObject)
 {
     NSLog(@"Response for #%d request is: %@",_currentPage,responseObject);
     _totalPages = [[responseObject objectForKey:@"total_pages"]integerValue];

     for (int i = 0;i<[[responseObject valueForKey:@"items"]count];i++)
     {
         Listing_Ads * ads = [[Listing_Ads alloc] initWithDictionary:[responseObject objectForKey:@"items"][i]];
         if (![self.ads_Array containsObject:ads])
         {
             [self.ads_Array addObject:ads];
         }
     }



在FirstVC.m中将数据传递到这里。
不知道到底该怎么做..如果我在这里错了,请纠正我..

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        Listing_Ads * selectedItem = self.ads_Array[indexPath.row];

        NSLog(@"ads%@",selectedItem);
        UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
        DetailsVC * vc = [storyboard instantiateViewControllerWithIdentifier:@"DetailsVC"];
        [self presentViewController:vc animated:YES completion:nil];
    }



in 详情VC.h

#import "Listing_Ads.h"
@class Listing_Ads;
@interface DetailsVC : NavigationHandler<UITableViewDataSource,UITableViewDelegate>
@property(strong,nonatomic) Listing_Ads * detailsListing;
@end


详细VC.m 我有

@interface DetailsVC ()
@end
@implementation DetailsVC
- (void)viewDidLoad
{
    // Update the user interface for the detail vehicle, if it exists.
    if (self.detailsListing)
    {
        //Set the View Controller title, which will display in the Navigation bar.
        NSLog(@"All Values here:%@",[self.detailsListing details_Listing]);
    }
}
这样做

,你甚至没有传递值:-

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
        DetailsVC * vc = [storyboard instantiateViewControllerWithIdentifier:@"DetailsVC"];
         //you missed this line-- pass value
         vc.detailsListing= [[Listing_Ads alloc] initWithDictionary:self.ads_Array[indexPath.row]];
        [self presentViewController:vc animated:YES completion:nil];
    }

最新更新