objective c - drawRect gets called on UIView subclass but not on UIViewController -


my code working far had create class uiview. bit inconvenient because need interact viewcontroller too.

btw, did try [self setneedsdisplay] on viewdidload of uiviewcontroller subclass file didn't work.

here's code, works on uiview subclass doesn't called on 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 try? btw, tabbar app. know can somehow block calls drawrect.

the tabs created programatically, not through 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 appreciate ideas. i've been through answers on site related setneedsdisplay not calling drawrect , haven't found answer particular case.

thanks.

you mixing 2 classes. uiviewcontroller not uiview, meaning doesn't inherits uiview. news has view, declared property: it's composition. drawrect method available in uiview class/subclass.

if force controller's view redraw can call

[self.view setneedsdisplay]; 

in viewcontroller.

you can set own custom view view of viewcontroller loadview method. this:

- (void)loadview {       mysubclassofuiview *rootview = [[mysubclassofuiview alloc] initwithframe:[[uiscreen mainscreen] bounds]];      // more view configuration ...      self.view = rootview;     [rootview release]; } 

so can keep drawing code separated in mysubclassofuiview.m file.

about uiviewcontroller:

the uiviewcontroller class provides fundamental view-management model iphone applications. basic view controller class supports presentation of associated view, support managing modal views, , support rotating views in response device orientation changes.

and purpose of uiview:

the uiview class defines rectangular area on screen , interfaces managing content in area. @ runtime, view object handles rendering of content in area , handles interactions content.

have @ cocoa core competencies / model-view-controller in apple's official documentation, describes mvc design pattern.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -