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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:19:42+00:00 2026-05-22T01:19:42+00:00

My code is working so far but I had to create a Class for

  • 0

My code is working so far but I had to create a Class for the UIView. This is a bit inconvenient because I need to interact with the ViewController too.

BTW, I did try [self setNeedsDisplay] on the ViewDidLoad of the UIViewController subclass file but it didn’t work.

Here’s the code, which works on UIView Subclass but doesn’t get called on a UIViewController one:

- (void)drawRect:(CGRect)rect
{
    UIColor *currentColor = [UIColor redColor];

    CGContextRef context = UIGraphicsGetCurrentContext();

    someNum = 1;
    CGContextBeginPath(context);
    CGContextMoveToPoint(context, 30, 40);
    [self addDotImageX:30 andY:40];

    CGContextSetLineWidth(context, 2);
    CGContextSetStrokeColorWithColor(context, currentColor.CGColor);
    CGContextStrokePath(context);
}

Any ideas on what to try? BTW, this is a TabBar App. I know those can somehow block the calls to drawRect.

The Tabs where created programatically, not through a Nib. Eg:

NSMutableArray *listOfViewControllers = [[NSMutableArray alloc] init];
UIViewController *vc;

vc = [[Education alloc] init];
vc.title = @"Education";
[listOfViewControllers addObject:vc];
vc.tabBarItem.image = [UIImage imageNamed:@"info.png"];
[vc release];

I would appreciate any ideas. I’ve been through the answers on this site related to setNeedsDisplay not calling drawRect and haven’t found an answer for my particular case.

Thanks.

  • 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-22T01:19:42+00:00Added an answer on May 22, 2026 at 1:19 am

    You are mixing up two classes. A UIViewController is not a UIView, meaning it doesn’t inherits from UIView. But the good news is it has a view, declared as property: It’s composition. The drawRect method is only available in a UIView class/subclass.

    If you like to force the controller’s view to redraw you can call

    [self.view setNeedsDisplay];
    

    in the viewController.

    You can set your own custom view as the view of your viewController with the loadView method. It could look like this:

    - (void)loadView
    {  
        MySubclassOfUIView *rootView = [[MySubclassOfUIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
        // do more view configuration ...
    
        self.view = rootView;
        [rootView release];
    }
    

    So you can keep your drawing code separated in your MySubclassOFUIView.m file.

    About the UIViewController:

    The UIViewController class provides
    the fundamental view-management model
    for iPhone applications. The basic
    view controller class supports the
    presentation of an associated view,
    support for managing modal views, and
    support for rotating views in response
    to device orientation changes.

    And the purpose of a UIView:

    The UIView class defines a rectangular
    area on the screen and the interfaces
    for managing the content in that area.
    At runtime, a view object handles the
    rendering of any content in its area
    and also handles any interactions with
    that content.

    Have a look at Cocoa Core Competencies / Model-View-Controller in Apple’s official documentation, it describes the MVC design pattern.

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

Sidebar

Related Questions

I have this code working in C#: var request = (HttpWebRequest)WebRequest.Create(https://x.com/service); request.Method = GET;
Simple question, how make this code working ? public class T { public static
I'm trying to get this piece of code working a little better. I suspect
I'm new to Django but I seem to have nearly identical code working on
I thought I had this all figured out, but now that I'm writing a
I have seen other people who have had this question, but most of the
This is probably a stupidly simple question, but I'm stuck. I had created a
I have had no trouble getting the sockets working with localips, but once I
I've read as much as I can, but totally stuck here (had it working
I'm trying to get some code working that a previous developer has written. Yep,

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.