2016-04-08 3 views
1

In meinem Projekt erhalte ich Daten von facebookSDK, wo ich Bilder anzeigen muss (wenn verfügbar), Nachricht (wenn verfügbar), Anzahl der Likes, Anzahl der Kommentare.Wie man Bedingungen für Bild und Nachricht schafft?

jetzt in meinen Daten ein Bild ist da aber Nachricht ist nicht verfügbar. Meine Zeichenfolge zeigt mir eine Nullnachricht. Jetzt muss ich 3 Bedingungen setzen.

können Sie verstehen, meine Frage kann mit unten Code sein.

 self.arrData = nil; 
     self.arrData = [[NSMutableArray alloc]init]; 
     self.arrData = [result[@"data"] mutableCopy]; 

     for (int i =0; i<self.arrData.count; i++) 
     { 

     NSString *strImage1 = [NSString stringWithFormat:@"%@",[[self.arrData objectAtIndex:i]valueForKey:@"full_picture"]]; 

     NSString *strComment =[NSString stringWithFormat:@"%@", [[self.arrData objectAtIndex:i ]valueForKey:@"message"]]; 
//in strComment i get @"(null)" message. 

     NSString *strLike = [NSString stringWithFormat:@"%@", [[[[self.arrData objectAtIndex:i]valueForKey:@"likes"]valueForKey:@"summary"]valueForKey:@"total_count"]]; 
     NSString *strCommentCount = [NSString stringWithFormat:@"%@", [[[[self.arrData objectAtIndex:i]valueForKey:@"comments"]valueForKey:@"summary"]valueForKey:@"total_count"]]; 

     NSString *strTime = [NSString stringWithFormat:@"%@",[[self.arrData objectAtIndex:i]valueForKey:@"created_time"]]; 


     CustomSocialView *imageView1 = [[CustomSocialView alloc] initWithFrame:CGRectMake(0, 0, width, 170)]; 

     [self.vLayout addSubview:imageView1]; 


     //conditions  
      if (strImage1 == nil)// if image is not available. 
      { 
       NSLog(@"no image"); 
       [imageView1 setContentText:strComment like:strLike comment:strCommentCount time:strTime]; 
      } 
      else if ([strCommentCount isEqual: 0]) // if Message is not available // may be here i am wrong. 
      { 
       NSLog(@"no msg"); 
       [imageView1 setImage:strImage1 like:strLike comment:strCommentCount time:strTime]; 
      } 
      else 
      { 
       NSLog(@"Both image and msg are available"); 
       [imageView1 setImage:strImage1 setContentText:strComment like:strLike comment:strCommentCount time:strTime]; 
      } 

jetzt bin ich verwirrt, dass, wie kann ich Bedingung für meinen Code machen.

bitte helfen Sie mir dafür.

Vielen Dank.

+0

Sie Ihre Antwortdaten auf Bilder oder Etiketten setzen? –

+0

was es bedeutet "isEqual: 0" Sie übergeben einen String-Wert, wie können Sie einen String-Wert zu Integer-Wert vergleichen. try @ "" statt 0 –

Antwort

1

Versuchen Sie folgendes:

for (int i = 0; i<self.arrData.count; i++) 
    { 
     //your code 

     if (strImage1 != nil && [strCommentCount intValue] != 0)// if image is not available. 
     { 
      NSLog(@"Both image and msg are available"); 
      [imageView1 setImage:strImage1 setContentText:strComment like:strLike comment:strCommentCount time:strTime]; 
     } 
     else 
     { 
      if ([strCommentCount intValue] != 0) 
      { 
       NSLog(@"no image"); 
       [imageView1 setContentText:strComment like:strLike comment:strCommentCount time:strTime]; 
      } 
      else 
      { 
       NSLog(@"no msg"); 
       [imageView1 setImage:strImage1 like:strLike comment:strCommentCount time:strTime]; 
      } 
     } 
    } 
+0

Vielen Dank @iOS_Binod. Ihr Code ist sehr hilfreich für mich. Es ist Arbeit, Sir !!! –

Verwandte Themen