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 8966071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:56:48+00:00 2026-06-15T16:56:48+00:00

I am making an app in which one of the view has a tableview.

  • 0

I am making an app in which one of the view has a tableview. Tableview cell has two conditions. There are two images which are going to be set on uitableview cell according to the condition i.e.

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *que =[[userqueries objectAtIndex:indexPath.row]objectForKey:@"question"];
    NSString *ans =[[userqueries objectAtIndex:indexPath.row]objectForKey:@"answer"];
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil){
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle   reuseIdentifier:CellIdentifier] autorelease];
        cell.imageView.image=nil;

        if ((que.length!=0)&&(ans.length!=0)) {
            UIImageView* imag = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 75)];
            imag.image = [UIImage imageNamed:@"ques.png"];
            [cell.contentView addSubview:imag];
            questext = [[UITextView alloc]initWithFrame:CGRectMake(10, 0, 300, 35)];
            questext.backgroundColor = [UIColor clearColor];
            questext.delegate = self;
            questext.tag = 101;
            questext.textAlignment = UITextAlignmentLeft;
            questext.editable = NO;
            questext.scrollEnabled = YES;
            [cell addSubview:questext];

            anstext = [[UITextView alloc]initWithFrame:CGRectMake(10, 37, 300, 35)];
            anstext.backgroundColor = [UIColor clearColor];
            anstext.delegate = self;
            anstext.tag = 102;
            anstext.scrollEnabled = YES;
            anstext.textAlignment = UITextAlignmentLeft;
            anstext.editable = NO;
            [cell addSubview:anstext];
        }
        else {
            UIImageView* imag = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 40)];
            imag.image = [UIImage imageNamed:@"answ.png"];
            [cell.contentView addSubview:imag];

            onlyques = [[UITextView alloc]initWithFrame:CGRectMake(10, 0, 300, 35)];
            onlyques.backgroundColor= [UIColor clearColor];
            [onlyques setScrollEnabled:YES];
            onlyques.delegate = self;
            onlyques.tag = 103;
            onlyques.textAlignment = UITextAlignmentLeft;
            onlyques.editable = NO;
            onlyques.scrollEnabled = YES;
            [cell addSubview:onlyques];
         }
    }
    questext = (UITextView*)[cell viewWithTag:101];
    questext.text = que;

    anstext = (UITextView*)[cell viewWithTag:102];
    anstext.text = ans;

    onlyques = (UITextView*)[cell viewWithTag:103];
    onlyques.text = que;

    return cell;
}

But image is not appearing properly. As I scroll up and down the table view ,images get changes automatically.

Please look upon my code and help me in finding the error.enter image description here

enter image description here

second image is when I scroll up and down the table view and first image is in the starting.

please help me. if any one knows how to load different images to uitableview cell.

thanks in advance.

  • 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-06-15T16:56:49+00:00Added an answer on June 15, 2026 at 4:56 pm

    Try this :

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
       NSString *que =[[userqueries objectAtIndex:indexPath.row]objectForKey:@"question"];
       NSString *ans =[[userqueries objectAtIndex:indexPath.row]objectForKey:@"answer"];
       static NSString *CellIdentifier = @"Cell";
       UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
       if (cell == nil)
       {
          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle   reuseIdentifier:CellIdentifier] autorelease];
          cell.imageView.image=nil;
       } 
       else
       {
          [cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
       }
    
       if ((que.length!=0)&&(ans.length!=0)) 
       {
            UIImageView* imag = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 75)];
            imag.image = [UIImage imageNamed:@"ques.png"];
            [cell.contentView addSubview:imag];
            questext = [[UITextView alloc]initWithFrame:CGRectMake(10, 0, 300, 35)];
            questext.backgroundColor = [UIColor clearColor];
            questext.delegate = self;
            questext.tag = 101;
            questext.textAlignment = UITextAlignmentLeft;
            questext.editable = NO;
            questext.scrollEnabled = YES;
            [cell addSubview:questext];
    
            anstext = [[UITextView alloc]initWithFrame:CGRectMake(10, 37, 300, 35)];
            anstext.backgroundColor = [UIColor clearColor];
            anstext.delegate = self;
            anstext.tag = 102;
            anstext.scrollEnabled = YES;
            anstext.textAlignment = UITextAlignmentLeft;
            anstext.editable = NO;
            [cell addSubview:anstext];
        }
        else 
        {
            UIImageView* imag = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 40)];
            imag.image = [UIImage imageNamed:@"answ.png"];
            [cell.contentView addSubview:imag];
    
            onlyques = [[UITextView alloc]initWithFrame:CGRectMake(10, 0, 300, 35)];
            onlyques.backgroundColor= [UIColor clearColor];
            [onlyques setScrollEnabled:YES];
            onlyques.delegate = self;
            onlyques.tag = 103;
            onlyques.textAlignment = UITextAlignmentLeft;
            onlyques.editable = NO;
            onlyques.scrollEnabled = YES;
            [cell addSubview:onlyques];
         }
    
         questext = (UITextView*)[cell viewWithTag:101];
         questext.text = que;
    
         anstext = (UITextView*)[cell viewWithTag:102];
         anstext.text = ans;
    
         onlyques = (UITextView*)[cell viewWithTag:103];
         onlyques.text = que;
    
         return cell;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making an app in which on one of the view I want
Iam making an app which has one index.php file. I also have these other
I'm making an app which has a tableview and a DetailViewController. I'm using Apple's
I'm making an app which has a flow roughly as below: User starts on
I'm making an android app which has to frequently call some .net web services
Suppose you are making a music library app. You have one view with a
How to change sizes of ViewController? I'm making simple app which uses deliberately two
I'm making a app with mutiple view controllers, one moves on to the next
I am making an app which has a section for latest company news. Basically
I am new android, i'm making an app in which one can download files

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.