2016-01-28 2 views
0

Я следую за шаблоном MVC для передачи данных, я не знаю, в чем проблема. Необходимо исправить это. Сценарий:
Я имею класс ListingItems т.е. модельiOS: требуется помощь в обмене данными


#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]; 

    } 



в DetailsVC.h

#import "Listing_Ads.h" 
@class Listing_Ads; 

@interface DetailsVC : NavigationHandler<UITableViewDataSource,UITableViewDelegate> 

@property(strong,nonatomic) Listing_Ads * detailsListing; 

@end 


В DetailVC.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]); 
    } 
} 
+0

Listing_Ads является NSObject Class или UIViewController? – Vvk

+0

Вы пропустили два основных кода: во-первых, во время хранения и, во-вторых, передачи объекта другому контроллеру. Покажите нам код для этого. – Vizllx

+0

Listing_Ads является классом NSObject – magid

ответ

0

ли, как это, вы даже не передавая значение: -

-(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

Я сделал это, но приложение рушится .. как-то ...! – magid

+0

Знаете ли вы, что такое отладка? Как установить точки останова в XCode. Вы знаете, как смотреть отчет об аварии? Если не Google это;) – Vizllx

+0

, пожалуйста, просто скажите мне, initWithDictionary, как вы присваиваете ему значение ..? – magid

Смежные вопросы