Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7518677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:47:01+00:00 2026-05-30T01:47:01+00:00

i m parsing json feed and according to the parsed value i m placing

  • 0

i m parsing json feed and according to the parsed value i m placing star images in table view cell.what i want is to place the star rating images as soon as the no of words in the textlabel gets completed the star rating images got to be flexible and not to have fixed frame. below is the code and screenshot of how the output got to look like.

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

//[tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

static NSString *CellIdentifier = @"Cell";
HJManagedImageV* mi;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    mi = [[[HJManagedImageV alloc] initWithFrame:CGRectMake(-18,-2,90,90)] autorelease];
    mi.tag = 999;
    [cell addSubview:mi];
}
else
{
    mi=(HJManagedImageV *)[cell viewWithTag:999];
    [mi clear];
}

NSDictionary *boy=[self.media1 objectAtIndex:indexPath.row];
NSString *str=[[NSString alloc]initWithFormat:@"%@",boy];
NSInteger n=[str intValue];
NSLog(@"the value:%@",str);

if(n ==0)
{   
    CGRect starFrame = CGRectMake(100,6, 85, 40);

    UIImageView *starImage = [[[UIImageView alloc] initWithFrame:starFrame] autorelease];
    starImage.image = [UIImage imageNamed:@"nostar.png"];
    starImage.backgroundColor=[UIColor clearColor];
    [cell.contentView addSubview:starImage];

    NSString *boo=[[NSString alloc]initWithFormat:@"%d",n];
    NSString *str=[[NSString alloc]initWithFormat:@"(%@)",boo];
    CGRect labelFrame = CGRectMake(290,18, 40, 40);
    UILabel *Label = [[[UILabel alloc] initWithFrame:labelFrame] autorelease];

    Label.text=str;
    Label.tag=1000;
  //  Label.backgroundColor=[UIColor clearColor];
    [cell.contentView addSubview:Label];


}
if(n >=1)
{   
    CGRect starFrame = CGRectMake(100,6, 85, 40);

    UIImageView *starImage = [[[UIImageView alloc] initWithFrame:starFrame] autorelease];
    starImage.image = [UIImage imageNamed:@"1star.png"];
    [cell.contentView addSubview:starImage];

    NSString *boo=[[NSString alloc]initWithFormat:@"%d",n];
    CGRect labelFrame = CGRectMake(290,18, 40, 40);
    UILabel *Label = [[[UILabel alloc] initWithFrame:labelFrame] autorelease];
    NSString *str=[[NSString alloc]initWithFormat:@"(%@)",boo];
    Label.text=str;
    Label.tag=1000;
   //Label.backgroundColor=[UIColor clearColor];
    [cell.contentView addSubview:Label];

}

if(n >=2)
{   
    CGRect starFrame = CGRectMake(100,6, 85, 40);

    UIImageView *starImage = [[[UIImageView alloc] initWithFrame:starFrame] autorelease];
    starImage.image = [UIImage imageNamed:@"twostar.png"];
    [cell.contentView addSubview:starImage];

    NSString *boo=[[NSString alloc]initWithFormat:@"%d",n];
      NSString *str=[[NSString alloc]initWithFormat:@"(%@)",boo];
    CGRect labelFrame = CGRectMake(290,18, 40,40);
    UILabel *Label = [[[UILabel alloc] initWithFrame:labelFrame] autorelease];
    Label.text=str;
    Label.tag=1000;
   // Label.backgroundColor=[UIColor clearColor];
    [cell.contentView addSubview:Label];

}
 if(n >=3)
{   
    CGRect starFrame = CGRectMake(100,6, 85, 40);

    UIImageView *starImage = [[[UIImageView alloc] initWithFrame:starFrame] autorelease];
    starImage.image = [UIImage imageNamed:@"threestar.png"];
    [cell.contentView addSubview:starImage];

    NSString *boo=[[NSString alloc]initWithFormat:@"%d",n];
    NSString *str=[[NSString alloc]initWithFormat:@"(%@)",boo];
    CGRect labelFrame = CGRectMake(290,18, 40,40);
    UILabel *Label = [[[UILabel alloc] initWithFrame:labelFrame] autorelease];
    Label.text=str;
    Label.tag=1000;
   Label.backgroundColor=[UIColor clearColor];
    [cell.contentView addSubview:Label];

}

  if(n >= 4)
{
    CGRect starFrame = CGRectMake(100,6, 85, 40);

    UIImageView *starImage = [[[UIImageView alloc] initWithFrame:starFrame] autorelease];
    starImage.image = [UIImage imageNamed:@"4star.png"];
    [cell.contentView addSubview:starImage];

    NSString *boo=[[NSString alloc]initWithFormat:@"%d",n];
     NSString *str=[[NSString alloc]initWithFormat:@"(%@)",boo];
    CGRect labelFrame = CGRectMake(290,18,40,40);
    UILabel *Label = [[[UILabel alloc] initWithFrame:labelFrame] autorelease];
    Label.text=str;
    Label.tag=1000;
   //Label.backgroundColor=[UIColor clearColor];
    [cell.contentView addSubview:Label];
}
if(n >= 5)
{
    CGRect starFrame = CGRectMake(100,6, 85, 40);

    UIImageView *starImage = [[[UIImageView alloc] initWithFrame:starFrame] autorelease];
    starImage.image = [UIImage imageNamed:@"5star.png"];
    [cell.contentView addSubview:starImage];

    NSString *boo=[[NSString alloc]initWithFormat:@"%d",n];
    NSString *str=[[NSString alloc]initWithFormat:@"(%@)",boo];
    CGRect labelFrame = CGRectMake(290,18, 40,40);
    UILabel *Label = [[[UILabel alloc] initWithFrame:labelFrame] autorelease];
    Label.font = [UIFont systemFontOfSize:18];
    Label.text=str;
    Label.tag=1000;
  // Label.backgroundColor=[UIColor clearColor];
    [cell.contentView addSubview:Label];
}

cell.textLabel.text=[self.story objectAtIndex:indexPath.row];
cell.textLabel.numberOfLines=2;

return cell;

 }

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:47:01+00:00Added an answer on May 30, 2026 at 1:47 am

    try out this code, i have solved

       - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        //[tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    
        static NSString *CellIdentifier = @"Cell";
        HJManagedImageV* mi;
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    //    if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
            mi = [[[HJManagedImageV alloc] initWithFrame:CGRectMake(-18,-2,90,90)] autorelease];
            mi.tag = 999;
            [cell addSubview:mi];
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        CGSize sizeTitle = [[self.story objectAtIndex:indexPath.row] sizeWithFont:[UIFont boldSystemFontOfSize:16.0] 
                                constrainedToSize:CGSizeMake(200, 40) 
                                    lineBreakMode:UILineBreakModeWordWrap];
    
        float width = sizeTitle.width;
        NSLog(@"Width %f", width);
        width = width+15;
        NSDictionary *boy=[self.media1 objectAtIndex:indexPath.row];
        NSString *str=[[NSString alloc]initWithFormat:@"%@",boy];
        NSInteger n=[str intValue];
        NSLog(@"the value:%@",str);
        CGRect coreFrame;
        if(width<170){
            coreFrame = CGRectMake(2, 6, width, 40);
        }
        else{
            coreFrame = CGRectMake(2, 6, 170, 40);   
            width = 175;
        }
         float k = width+85;
        UILabel *lab = [[UILabel alloc] initWithFrame:coreFrame];
        lab.text = [self.story objectAtIndex:indexPath.row];
        [cell.contentView addSubview:lab];
    
        if(n ==0)
        {   
            CGRect starFrame = CGRectMake(width,6, 85, 37);
    
            UIImageView *starImage = [[[UIImageView alloc] initWithFrame:starFrame] autorelease];
            starImage.image = [UIImage imageNamed:@"nostar.png"];
            starImage.backgroundColor=[UIColor clearColor];
            [cell.contentView addSubview:starImage];
    
            NSString *boo=[[NSString alloc]initWithFormat:@"%d",n];
            NSString *str=[[NSString alloc]initWithFormat:@"(%@)",boo];
           // str=[str substringToIndex:4];
            CGRect labelFrame = CGRectMake(k,6, 40, 40);
            UILabel *Label = [[[UILabel alloc] initWithFrame:labelFrame] autorelease];
    
            Label.text=str;
            Label.tag=1000;
              Label.textColor=[UIColor grayColor];
            [cell.contentView addSubview:Label];
    
    
        }
        if(n >=1)
        {   
            CGRect starFrame = CGRectMake(width,6, 85, 37);
    
            UIImageView *starImage = [[[UIImageView alloc] initWithFrame:starFrame] autorelease];
            starImage.image = [UIImage imageNamed:@"1star.png"];
            [cell.contentView addSubview:starImage];
    
            NSString *boo=[[NSString alloc]initWithFormat:@"%d",n];
            CGRect labelFrame = CGRectMake(k,6, 40, 40);
            UILabel *Label = [[[UILabel alloc] initWithFrame:labelFrame] autorelease];
            NSString *str=[[NSString alloc]initWithFormat:@"(%@)",boo];
            Label.text=str;
            Label.tag=1000;
              Label.textColor=[UIColor grayColor];
            [cell.contentView addSubview:Label];
        }
        if(n >=2)
        {   
            CGRect starFrame = CGRectMake(width,6, 85, 37);
    
            UIImageView *starImage = [[[UIImageView alloc] initWithFrame:starFrame] autorelease];
            starImage.image = [UIImage imageNamed:@"twostar.png"];
            [cell.contentView addSubview:starImage];
    
            NSString *boo=[[NSString alloc]initWithFormat:@"%d",n];
              NSString *str=[[NSString alloc]initWithFormat:@"(%@)",boo];
            CGRect labelFrame = CGRectMake(k,6, 40,40);
            UILabel *Label = [[[UILabel alloc] initWithFrame:labelFrame] autorelease];
                   Label.text=str;
            Label.tag=1000;
              Label.textColor=[UIColor grayColor];
           // Label.backgroundColor=[UIColor clearColor];
            [cell.contentView addSubview:Label];
        }
         if(n >=3)
        {   
            CGRect starFrame = CGRectMake(width,6, 85, 37);
    
            UIImageView *starImage = [[[UIImageView alloc] initWithFrame:starFrame] autorelease];
            starImage.image = [UIImage imageNamed:@"threestar.png"];
            [cell.contentView addSubview:starImage];
    
            NSString *boo=[[NSString alloc]initWithFormat:@"%d",n];
            NSString *str=[[NSString alloc]initWithFormat:@"(%@)",boo];
          //  str=[str substringToIndex:4];
    
            CGRect labelFrame = CGRectMake(k,6, 40,40);
            UILabel *Label = [[[UILabel alloc] initWithFrame:labelFrame] autorelease];
    
            Label.text=str;
            Label.tag=1000;
              Label.textColor=[UIColor grayColor];
                [cell.contentView addSubview:Label];
    
        }
       if(n >= 4)
        {
            CGRect starFrame = CGRectMake(width,6, 85, 37);
    
            UIImageView *starImage = [[[UIImageView alloc] initWithFrame:starFrame] autorelease];
            starImage.image = [UIImage imageNamed:@"4star.png"];
            [cell.contentView addSubview:starImage];
    
            NSString *boo=[[NSString alloc]initWithFormat:@"%d",n];
             NSString *str=[[NSString alloc]initWithFormat:@"(%@)",boo];
            //str=[str substringToIndex:4];
    
            CGRect labelFrame = CGRectMake(k,6,40,40);
            UILabel *Label = [[[UILabel alloc] initWithFrame:labelFrame] autorelease];
    
            Label.text=str;
            Label.tag=1000;
            Label.textColor=[UIColor grayColor];
           //Label.backgroundColor=[UIColor clearColor];
            [cell.contentView addSubview:Label];
        }
        if(n >= 5)
        {
            CGRect starFrame = CGRectMake(width,6, 85, 37);
    
            UIImageView *starImage = [[[UIImageView alloc] initWithFrame:starFrame] autorelease];
            starImage.image = [UIImage imageNamed:@"5star.png"];
            [cell.contentView addSubview:starImage];
    
            NSString *boo=[[NSString alloc]initWithFormat:@"%d",n];
            NSString *str=[[NSString alloc]initWithFormat:@"(%@)",boo];
           // str=[str substringToIndex:4];
    
            CGRect labelFrame = CGRectMake(k,6, 40,40);
            UILabel *Label = [[[UILabel alloc] initWithFrame:labelFrame] autorelease];
            Label.font = [UIFont systemFontOfSize:18];
    
            Label.text=str;
            Label.tag=1000;
            Label.textColor=[UIColor grayColor];
          // Label.backgroundColor=[UIColor clearColor];
            [cell.contentView addSubview:Label];
        }
        return cell;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I m parsing a json feed and populating my table view.if my parsed value
i m parsing a json feed .using async image download I m downloading images
I'm parsing a json feed routinely and need to insert only the newest users
I'm parsing a date from a JSON event feed - but the date shows
I m parsing a json feed containing three tags they are Name,Status,Image and storing
I am parsing JSON from a URL & displaying it in a list view(ofc
I need help with parsing of JSON feed text returned from Twitter. I need
Parsing JSON in PHP My variable jsonvar is in the form of {rating:good} Once
I am parsing two json feeds. The first json feed parses pharmacies of a
I am downloading and parsing JSON objects to build a news feed to populate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.