2016-04-26 6 views
0

Ein Problem mit einer Tabellenansicht Download von Daten aus einer JSON-Datei. Der JSON hat 4 Einträge und ich möchte, dass mein Code den ersten Eintrag ignoriert und einfach die ersten nach der ersten in die Tabellenansicht einfügt. Mit meinem Code unten erhält es die vollen 4 Einträge vom JSON und platziert sie alle in der Tabellenansicht. Ich habe alles versucht, aber ich kann meinen Kopf damit nicht umgehen.Ziel C JSON nicht ersten Eintrag auslassen

Danke,

CurtisB

#import "TutorProfileView.h" 

    @interface TutorProfileView() 

    @end 

    @implementation TutorProfileView 
    NSDictionary *TutordizDict = @""; 
    NSMutableArray *TutordaObj; 
    NSDictionary *Tutordadict; 
    NSArray *Tutortrackinbud; 


    - (void)viewDidLoad { 
     [super viewDidLoad]; 
     [self downloadreviews]; 
    } 

    - (void)didReceiveMemoryWarning { 
     [super didReceiveMemoryWarning]; 
     // Dispose of any resources that can be recreated. 
    } 
    -(UIStatusBarStyle)preferredStatusBarStyle{ 
     return UIStatusBarStyleLightContent; 
    } 
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 

    { 
     NSArray *udropofftrack = [TutordizDict objectForKey:@"tutific"]; 
     return [udropofftrack count]; 

    } 

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 

    { 

     return 88; 

    } 

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

    { 

     static NSString *simpleTableIdentifier = @"TableViewCell2"; 



     TableViewCell2 *cell = (TableViewCell2 *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 

     if (cell == nil) 

     { 

      NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:@"TableViewCell2" owner:self options:nil]; 

      cell = [nibArray objectAtIndex:0]; 

     } 
     cell.name.text = [NSMutableString stringWithFormat:@"%@",[Tutortrackinbud[indexPath.row] valueForKey:@"username"]]; 

     return cell; 
    } 

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

    { 

    } 
    -(void)downloadreviews 
    { 

     NSString *subjects2 = @"tutor1"; 

     NSURL *blogURL = [NSURL URLWithString:[NSString stringWithFormat:@"getreviews.php?username=%@", subjects2]]; 
     NSLog(@"URL = %@", blogURL); 

     NSData *jsonData = [NSData dataWithContentsOfURL:blogURL]; 

     if(jsonData == nil) 
     { 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Error" message:@"Please check your internet connection and try again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
      [alert show]; 
      return; 
     } 
     else{ 

      NSError *error = nil; 
      TutordizDict = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error]; 
      Tutortrackinbud = [TutordizDict objectForKey:@"tutific"]; 

      NSUInteger *elements = [Tutortrackinbud count]; 
      NSLog(@"Number of Shows : %d", elements); 

      if (elements == 0) 
      { 
       //[udropofftrack removeAllObjects]; 
       Tutortrackinbud=nil; 
       [_tableViewObject reloadData]; 
       // self.noorder.hidden=FALSE; 

      } 


      else{ 

       NSString *success = [Tutortrackinbud[0] valueForKey:@"success"]; 
       if ([success isEqual: @"0"]) 
       { 
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Error" message:@"Your application failed to connect to uDropOff servers. Please update your application in the App Store." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
        [alert show]; 
        return; 

       } 
       else 
       { 

        { 
         for (int i = 1 ; i < [Tutortrackinbud count]; i++){ 
          { 
           TutordaObj = [[NSMutableArray alloc] init]; 

          } 
         } 
        } 
       } 
      } 
     } 
     [_tableViewObject reloadData]; 
    } 

    @end 
+0

Sie sind nicht wirklich etwas mit der Antwort zu tun. Sie greifen noch auf die Daten von "TutordizDict" zu – Joshua

Antwort

1

Wenn ich Ihre Frage richtig verstanden wollten Sie nur das erste Element/Eintrag aus dem Array überspringen. warum nicht nur Tutortrackinbud

Beispiel verwenden:

-(void)downloadreviews{ 

    //<fetch data>... 

     NSError *error = nil; 
     TutordizDict = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error]; 
     NSMutableArray *temp = [[TutordizDict objectForKey:@"tutific"]mutableCopy]; 

     if([temp count] > 0){ // if there is an entry should we remove it, if we should just perform this; otherwise if we only remove if there are more than 1 change condition to 1 
      [temp removeObjectAtIndex:0]; 
     } 

     Tutortrackinbud = [temp copy]; 
     NSUInteger *elements = [Tutortrackinbud count]; 
     NSLog(@"Number of Shows : %d", elements); 

     if (elements == 0) 
     { 
      //[udropofftrack removeAllObjects]; 
      Tutortrackinbud=nil; 
      [_tableViewObject reloadData]; 
      // self.noorder.hidden=FALSE; 

     } 


     else{ 

      NSString *success = [Tutortrackinbud[0] valueForKey:@"success"]; 
      if ([success isEqual: @"0"]) 
      { 
       UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Error" message:@"Your application failed to connect to uDropOff servers. Please update your application in the App Store." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
       [alert show]; 
       return; 

      } 
      else 
      { 

       { 
        for (int i = 1 ; i < [Tutortrackinbud count]; i++){ 
         { 
          TutordaObj = [[NSMutableArray alloc] init]; 

         } 
        } 
       } 
      } 
     } 
    } 
    [_tableViewObject reloadData]; 
}` 
+0

Ich habe diesen Code ausprobiert und erhalte den folgenden Fehler .. *** Beenden der App aufgrund der nicht abgefangenen Ausnahme 'NSRangeException', Grund: '- [__ NSCFArray objectAtIndex:]: index (3) über Grenzen (3)‘ –

+0

Verstanden durch den Ersatz meiner Zählung für die Zellen arbeiten mit - (NSInteger) tableview: (UITableView *) tableview numberOfRowsInSection: (NSInteger) Abschnitt { return [Tutortrackinbud count]; } –