Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Need help retrieving JSON response object data issue with NSDictionary and NSArray

jessetavjessetav New YorkPosts: 9 Noob
edited September 2014 in iOS SDK Development
I have a JSON response object that is stored as shown below:
ownerEvents = [NSMutableArray arrayWithArray:[(NSDictionary *)responseObject objectForKey:@result]];

ownerEvents stores the JSON below (retrieved via xcode debug window):
2014-09-17 01:23:49.311 test123[31919:60b] JSON: {
    result =     (
                {
            "end_time" = "4:00AM";
            "event_date" = "09-16-2014";
            "event_id" = 89;
            "event_image" = "http://www.jessetaveras.com/test123/images/event_flyers/event1141091689687507968f3f78ac5f23b2a954bb1dc6d.png";
            "event_price" = 30;
            "event_tickets_total" = 250;
            "event_title" = dfjjsnda;
            "start_time" = "5:00AM";
            "venue_name" = "the shit box";
            weekday = Tuesday;
        }{
            "end_time" = "4:00AM";
            "event_date" = "09-16-2014";
            "event_id" = 89;
            "event_image" = "http://www.jessetaveras.com/test123/images/event_flyers/event1141091689687507968f3f78ac5f23b2a954bb1dc6d.png";
            "event_price" = 30;
            "event_tickets_total" = 250;
            "event_title" = dfjjsnda;
            "start_time" = "5:00AM";
            "venue_name" = "the shit box";
            weekday = Tuesday;
        }
    );
    }

The JSON above is then split into 2 different cells in a table view

I need to send the data of an individual cell to another view controller. Inside the function that is supposed to send the data to the other view controller I have this code:

within the cell class I have:
@property (strong, nonatomic) IBOutlet UIButton *editButtonPressed;

within CellForRowAtIndexPath (which is in a UIViewController) I have:

    - (UITableViewCell *)tableView:(UITableView *)tableView   cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    static NSString *CellIdentifier = @OwnerCell;
    
    TDOwnerViewCell *historyCell = [tableView  dequeueReusableCellWithIdentifier:CellIdentifier ];
    historyCell.selectionStyle =  UITableViewCellSelectionStyleNone;
    //NSLog(@THIS IS current Cell %@", [ownerEvents  objectAtIndex:indexPath.row]);
        
    [historyCell configOwnerEventCell:[ownerEvents objectAtIndex:indexPath.row]];
     
    [historyCell.editButtonPressed addTarget:self action:@selector(editButtonPressed:)  forControlEvents:UIControlEventTouchUpInside];
    historyCell.editButtonPressed.tag = indexPath.row;
    if(historyCell == nil)
    {
    historyCell = [[TDOwnerViewCell alloc]  initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:@OwnerCell];
    }
    return historyCell;    
    }

This is the method being called when the button is pressed:
- (void)editButtonPressed:(UIButton *) editButtonPressed{
    UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@Main_iPhone bundle:nil];
    
    TDEventEditViewController * vc3 = [storyboard instantiateViewControllerWithIdentifier:@eventEditView];
    
    [historyCell configOwnerEventCell:[ownerEvents objectAtIndex:indexPath.row]];
    NSInteger index = editButtonPressed.tag;
    //I am almost 100% sure that the error is within the next 3 lines of code. when I comment them out I get no error.
    NSArray *eventsJSONData = [ownerEvents objectAtIndex:index];
    ownerEvents = [NSMutableArray arrayWithArray:[(NSDictionary *)responseObject objectForKey:@result]];

    vc3.detailDic = eventsJSONData[index];
   
    [self.navigationController pushViewController:vc3 animated:YES];
    }


I am getting this error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary objectAtIndexedSubscript:]: unrecognized selector sent to instance 0xca53b50'

I am using xcod 5, target ios 7. Please help, I never seem to figure these errors out. Thanks in advance.
Post edited by jessetav on

Replies

  • jessetavjessetav New YorkPosts: 9 Noob
    I figured it out. This fixed the issue:
    - (void)editButtonPressed:(UIButton *) editButtonPressed{
        UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@Main_iPhone bundle:nil];
        
         TDEventEditViewController * vc3 = [storyboard instantiateViewControllerWithIdentifier:@eventEditView];
        
        NSInteger index = editButtonPressed.tag;
        NSLog(@index %ld, (long)index);
        
      
        vc3.detailDic = [self.ownerEvents objectAtIndex:index];
       
        
        [self.navigationController pushViewController:vc3 animated:YES];
    }
    
Sign In or Register to comment.