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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:04:56+00:00 2026-05-30T08:04:56+00:00

I have a table view with a custom cell (governed by a custom class

  • 0

I have a table view with a custom cell (governed by a custom class of course) that has the following drawRect: function in the custom class:

- (void)drawRect:(CGRect)rect
{
    [super drawRect:rect];
    CGRect busNumberFrame = busNumber.frame;

    NSLog(@"-----------------");
    NSLog(@"Line Origin X: %f", busNumberFrame.origin.x + busNumberFrame.size.width);
    NSLog(@"Line Origin Y: %f", self.frame.origin.y);
    NSLog(@"Line End X: %f", busNumberFrame.origin.x + busNumberFrame.size.width);
    NSLog(@"Line End Y: %f", self.frame.origin.y + self.frame.size.height);
    NSLog(@"-----------------");

    CGContextRef cgContext = UIGraphicsGetCurrentContext();
    CGContextSetRGBStrokeColor(cgContext, 0.0, 0.0, 0.0, 1.0);
    CGContextSetLineWidth(cgContext, 0.75);
    CGContextMoveToPoint(cgContext, busNumberFrame.origin.x + busNumberFrame.size.width, self.frame.origin.y);
    CGContextAddLineToPoint(cgContext, busNumberFrame.origin.x + busNumberFrame.size.width, self.frame.origin.y + self.frame.size.height);
    CGContextStrokePath(cgContext);
}

This draws a line from the top of the cell to the bottom. This gets drawn successfully for the first cell but the subsequent cells don’t show the line that’s supposed to be drawn. Here is the code for cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    BusInfoTableViewCell *cell = (BusInfoTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"Bus Route Cell"];

    Bus *bus = [self.fetchedResultsController objectAtIndexPath:indexPath];
    // Configure the cell...

    cell.busNumber.text = [bus.number stringValue];
    cell.firstStop.text = bus.departure;
    cell.lastStop.text = bus.arrival;
    [cell.contentView setNeedsDisplay];
    return cell;
}

And here is the log output of drawRect::

2012-02-21 19:35:08.840 ETA[2208:707] -----------------
2012-02-21 19:35:08.843 ETA[2208:707] Line Origin X: 79.000000
2012-02-21 19:35:08.843 ETA[2208:707] Line Origin Y: 0.000000
2012-02-21 19:35:08.844 ETA[2208:707] Line End X: 79.000000
2012-02-21 19:35:08.845 ETA[2208:707] Line End Y: 63.000000
2012-02-21 19:35:08.845 ETA[2208:707] -----------------
2012-02-21 19:35:08.850 ETA[2208:707] -----------------
2012-02-21 19:35:08.851 ETA[2208:707] Line Origin X: 79.000000
2012-02-21 19:35:08.852 ETA[2208:707] Line Origin Y: 63.000000
2012-02-21 19:35:08.852 ETA[2208:707] Line End X: 79.000000
2012-02-21 19:35:08.853 ETA[2208:707] Line End Y: 126.000000
2012-02-21 19:35:08.853 ETA[2208:707] -----------------
2012-02-21 19:35:08.857 ETA[2208:707] -----------------
2012-02-21 19:35:08.857 ETA[2208:707] Line Origin X: 79.000000
2012-02-21 19:35:08.858 ETA[2208:707] Line Origin Y: 126.000000
2012-02-21 19:35:08.859 ETA[2208:707] Line End X: 79.000000
2012-02-21 19:35:08.859 ETA[2208:707] Line End Y: 189.000000
2012-02-21 19:35:08.860 ETA[2208:707] -----------------

I’m probably doing something wrong…

Any help is appreciated.

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-05-30T08:04:58+00:00Added an answer on May 30, 2026 at 8:04 am

    The coordinates are local for the cell, so you should be using the following (all instances of self.frame should be self.bounds):

    - (void)drawRect:(CGRect)rect {
        [super drawRect:rect];
        CGRect busNumberFrame = busNumber.frame;
    
        NSLog(@"-----------------");
        NSLog(@"Line Origin X: %f", busNumberFrame.origin.x + busNumberFrame.size.width);
        NSLog(@"Line Origin Y: %f", self.bounds.origin.y);
        NSLog(@"Line End X: %f", busNumberFrame.origin.x + busNumberFrame.size.width);
        NSLog(@"Line End Y: %f", self.bounds.origin.y + self.bounds.size.height);
        NSLog(@"-----------------");
    
        CGContextRef cgContext = UIGraphicsGetCurrentContext();
        CGContextSetRGBStrokeColor(cgContext, 0.0, 0.0, 0.0, 1.0);
        CGContextSetLineWidth(cgContext, 0.75);
        CGContextMoveToPoint(cgContext, busNumberFrame.origin.x + busNumberFrame.size.width, self.bounds.origin.y);
        CGContextAddLineToPoint(cgContext, busNumberFrame.origin.x + busNumberFrame.size.width, self.bounds.origin.y + self.bounds.size.height);
        CGContextStrokePath(cgContext);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table view that has custom cells. In every cell I have
I have a custom Table View Cell that displays the details of a Conference
I have a custom cell that contains a button in a table view. The
I have a custom view in a custom table cell. Every time a specific
I have a custom cell and i displayed that custom cell in a table
I have custom table view cell with images (loaded from app document directory), labels,
I have a table view with custom cells and I recognize swipes in that
i have a not custom table view view that i mean that i'm using
I have an table view where i am loaded custom cell from different nib,
I have a table view of custom cells representing individual uploads and each cell

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.