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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:19:22+00:00 2026-06-10T10:19:22+00:00

I’m creating a UITableView that uses custom UITableViewCell classes. The UITableViewCell uses it’s own

  • 0

I’m creating a UITableView that uses custom UITableViewCell classes. The UITableViewCell uses it’s own methods to lay itself out depending on the indexPath and selected index.

Code is as follows:
AgendaView.h
TableViewDelegate Methods

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

EventInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"infoCell"];
if(cell == nil){
    cell = [[EventInfoCell alloc]initWithStyle:0 reuseIdentifier:@"infoCell"];
}

cell.frame = CGRectMake(0, 0, 320, [self tableView:tableView heightForRowAtIndexPath:indexPath]);
cell.selectedBackgroundView = nil;
cell.delegate = self;

TimerEvent *event = [_eventsArray objectAtIndex:indexPath.row];
EventInfo *info = [event valueForKey:@"eventInfo"];

NSDateFormatter *df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"h:mma"];
cell.timeLabel.text = [NSString stringWithFormat:@"%@",[df stringFromDate:event.date]];

cell.titleField.text = [info title];

cell.bgImageView.frame = cell.frame;

cell.countdownLabel.text = [self getCountdown:event];

if (_selectedIndex == indexPath.row){
    [cell layoutSelected:YES editing:[tableView isEditing]];

    if ([info location]) 
        cell.locationField.text =[NSString stringWithFormat:@"@%@",[info location]];
    else
        cell.locationField.text = @"Location";

    if ([info notes]) 
        cell.notesView.text = [info notes];
    else
        cell.notesView.text = @"Notes";
}else
    [cell layoutSelected:NO editing:NO];

return cell;
}

Is this an acceptable way to layout a cell? Or should I create different cell subclasses for the different cell layouts? If it helps, the cell’s expand when touched to show more information, which is why I had the subclass handle it’s own layouts.

Images: http://tinypic.com/r/2vjpi12/6

The cells information is determined by the TimerEvent/Info assigned during tableView:cellForRowAtIndexPath.

  • 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-10T10:19:23+00:00Added an answer on June 10, 2026 at 10:19 am

    I think you should instead create different UITableViewCell subclasses for each type of row. This is a sketch of how I might do it:

    @interface UITableViewCell (MyTableViewSupport)
    @property ( nonatomic, strong ) id value ; // value to display
    +(NSString *)identifier ; // reuse identifier for this class
    @end
    
    @implementation UITableViewCell (MyTableViewSupport)
    
    +(NSString*)identifier
    {
        return NSStringFromClass( self ) ;
    }
    
    const char * sValueKey = "TableCellValue";
    -(void)setValue:(id)value
    {
        objc_setAssociatedObject( self, sValueKey, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC ) ;
    }
    
    -(id)value
    {
        return objc_getAssociatedObject( self, sValueKey ) ;
    }
    
    @end
    
    @interface TableCellA : TableViewCell
    @end
    
    @interface TableCellB : TableViewCell
    @end
    
    @implementation TableCellA
    
    -(void)layoutSubviews
    {
        // one type of layout
    }
    
    @end
    
    @implementation TableCellB
    
    -(void)layoutSubviews
    {
        // another type of layout
    }
    
    @end
    

    Your table view data source (probably your view controller):

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        id value = [ self _valueForRowAtIndexPath ] ;
        Class cellClass = /// ...look up cell class based on section/row or type of value, etc.
    
        UITableViewCell * cell = [ tableView dequeueReusableCellWithIdentifier:cellClass.identifier ] ;
        if ( !cell )
        {
            cell = [ [ cellClass alloc ] init ] ;
        }
    
        cell.value = value ;
        return cell ;
    }
    

    EDIT: extended explanation of the above:

    The first part of the code (the category) on UITableViewCell extends it to provide a cellIdentifier class method and a value property. Now all instances of UITableViewCell support setting/getting the “value” property, including your subclasses.

    Let’s say you have to types of row, Employees and Companies. You would create EmployeeCell and CompanyCell:

    @interface EmployeeCell : UITableViewCell
    
    -(void)layoutSubviews
    {
        // layout code for employee cells
    }
    
    -(void)setValue:(id)value
    {
        [ super setValue:value ] ;
        // configure the subviews of this employee cell (first name label, last name label, photo, for example) based on `value`
    }
    
    @end
    
    @implementation CompanyCell : UITableViewCell
    
    -(void)layoutSubviews
    {
        // layout code for company cells
    }
    
    -(void)setValue:(id)value
    {
        [ super setValue:value ] ;
    
        // configure the subviews of this company cell (company name label, address label, CEO label, for example) based on `value`
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.