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

  • SEARCH
  • Home
  • 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 6553059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:32:08+00:00 2026-05-25T12:32:08+00:00

I created contentViews and assigned tags. When I click row in simulator, I cannot

  • 0

I created contentViews and assigned tags. When I click row in simulator, I cannot get right tag value. Tag value is always 0.
What is wrong with my code?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{       
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];   

    UIImageView *imgView, *imgView1;   
    if(cell == nil)   
    {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];     
        cell.textLabel.text = @"test";

        imgView = [[UIImageView alloc] initWithFrame:CGRectMake(100,0,20,62)];
        [imgView setImage:[UIImage imageNamed:@"1.png"]];
        imgView.tag = 10;
        [cell.contentView addSubview:imgView];
        [imgView release];

        imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(200,0,20,62)];
        [imgView1 setImage:[UIImage imageNamed:@"2.png"]];
        imgView1.tag = 20;
        [cell.contentView addSubview:imgView1];
        [imgView1 release];

    }
    else
    {
        imgView = (id)[cell.contentView viewWithTag:10];
        imgView1 = (id)[cell.contentView viewWithTag:20];
    }   
    return cell;
}

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

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (cell.contentView.tag == 10) // tag is always 0. What's wrong?
        NSLog(@"10");
    else if (cell.contentView.tag == 20)
        NSLog(@"20");
}
  • 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-25T12:32:09+00:00Added an answer on May 25, 2026 at 12:32 pm

    You’re querying the tag of the contentview, but adding the tag to a subview of the contentview.

    CellView
        ContentView    //You're asking for the tag of this
            Subview    //But assigning the tag to this
    

    Try ((UIView*)[cell.contentview subviews] objectAtIndex:0]).tag

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a few mediawiki custom tags, using the guide found here http://www.mediawiki.org/wiki/Manual:Tag_extensions I
I created a single page (with code behind .vb) and created Public intFileID As
I have created an application that creates notifications, using the following code: // notification
I have created a UITableView with two cells, username and password using the code
I have created a subclass of UIControl called ToggleImageControl via the following code (with
I have created one application in which if i select on particular row in
I have created a UITableView with two cells, username and password using the code
The below code works fine when i am not adding any extra row all
Created .NET WCF service, tested it - works. Generated schemas from Data and service
I created a program using dev-cpp and wxwidgets which solves a puzzle. The user

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.