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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:39:09+00:00 2026-05-27T15:39:09+00:00

I ran into this issue twice now, and am curious to know if there

  • 0

I ran into this issue twice now, and am curious to know if there is a correct way of getting the following example to work. I know there are other ways /workarounds for doing the same thing but I am wondering why the compiler doesn’t recognise my casting and if I am missing something obvious here.

Suppose I have two table views with different style header views that I need to provide. SectionHeaderViewA is a UIView subclass with a custom property textLabelA, SectionHeaderViewB is also a UIView subclass with a custom property textLabelB.

In the method:

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    id headerView;
    if (tableView.tag == TAG_A)
    {
        headerView = (SectionHeaderViewA*)[[SectionHeaderViewA alloc] init];
        headerView.textLabelA = ... // I am unable to access the custom property here even after casting (SectionHeaderViewA*) above.
    } else if (tableView.tag == TAG_B) {
        headerView = (SectionHeaderViewB*)[[SectionHeaderViewB alloc] init];
        headerView.textLabelB = ... // Same as above, even after casting the custom property is not recognised
    }
    return headerView;
}

Even after casting (SectionHeaderViewA*) and (SectionHeaderViewB*) to my headerView ivar, I am still unable to access their respective custom properties. It’s like the compiler is still seeing headerView as an unknown / id type but why?

  • 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-27T15:39:09+00:00Added an answer on May 27, 2026 at 3:39 pm

    The cast is not in the correct place. Cast headerView before sending the appropriate textLabel A or B message.

    id headerView;
    if (tableView.tag == TAG_A)  
    {  
        headerView = [[SectionHeaderViewA alloc] init];
        ((SectionHeaderViewA*)headerView).textLabelA = ... // I am unable to access the custom property here even after casting (SectionHeaderViewA*) above.
    } else if (tableView.tag == TAG_B) {
        headerView = [[SectionHeaderViewB alloc] init];
        ((SectionHeaderViewB*)headerView).textLabelB = ... // Same as above, even after casting the custom property is not recognized
    }
    return headerView;  
    

    Once you move the cast, you will be able to send the correct message.

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

Sidebar

Related Questions

This originally was a problem I ran into at work, but is now something
I ran into this issue while testing a rails app deployed to two different
Never ran into this problem with jQuery before. I have the following: $(document).ready(function() {
I ran into this issue when trying to add a CMFCMenuButton to an existing
Has anyone ran into this issue? We have a mobile site that can't use
I ran into this issue quite a few times. Let's say I have a
I ran into this issue on accident while debugging a faulty string trim function
I'm trying to create a website for myself and just ran into this issue:
I was helping someone with their homework and ran into this strange issue. The
Edit: it's been ages since I've ran into this "issue" back then, and by

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.