PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, June 29, 2022

[FIXED] how to make condition for image and message?

 June 29, 2022     facebook-sdk-4.0, image, ios, iphone, null     No comments   

Issue

in my project i get data from facebookSDK where I need to display images(if available), message(if available), numbers of likes, numbers of comments.

now in my data one image is there but message is not available. my string show me null message. now i need to put 3 conditions.

you can understand my question may be with below code.

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

now i am confused that how can i make condition for my code.

please help me for this.

Thank you.


Solution

Try this:

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


Answered By - dev_binod
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing