首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS :需要数据通信帮助

iOS :需要数据通信帮助
EN

Stack Overflow用户
提问于 2016-01-28 06:05:53
回答 1查看 29关注 0票数 0

我遵循MVC模式进行数据通信,我不知道到底发生了什么问题。需要解决这个问题。设想情况是:

我有一个ListingItems的类,即:模型

代码语言:javascript
复制
#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

代码语言:javascript
复制
@property (nonatomic, retain) NSMutableArray * ads_Array;

在FirstVC.m

代码语言:javascript
复制
[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这里传递数据..。

不知道到底该怎么做。如果我错了请纠正我..。

代码语言:javascript
复制
 -(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];

    }

在DetailsVC.h

代码语言:javascript
复制
#import "Listing_Ads.h"
@class Listing_Ads;

@interface DetailsVC : NavigationHandler<UITableViewDataSource,UITableViewDelegate>

@property(strong,nonatomic) Listing_Ads * detailsListing;

@end

在DetailVC.m我有

代码语言:javascript
复制
@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]);
    }
}
EN

回答 1

Stack Overflow用户

发布于 2016-01-28 07:43:59

这样做,你甚至没有传递这个值:-

代码语言:javascript
复制
 -(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];

    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35053953

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档