tags:

views:

37

answers:

1

Hi, i have done the following...tran is a UIView...doSomething is a methos in UIView.but i cant call that method from viewdidload? any help please?

- (void)viewDidLoad 

tran *m_view = [[tran alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[self.view addSubview:m_view];
[m_view release];
tran *s = (tran *)self.view;
[s doSomthing];
[super viewDidLoad];

}

+2  A: 
  1. Your subclass of UIView should be capitalized to Tran for readability (class names are capitalized)
  2. You are adding m_view to the view controller's view via -addSubview:
  3. Therefore, the view controller view has a subviews array, and that array contains an object instance of type Tran *
  4. However, neither using -addSubview: nor casting via (Tran *) makes the view controller view of type Tran.
  5. The view controller's view is still of type UIView
  6. Therefore, you cannot call Tran's -doSomething on the view controller's view, because that view is not of type Tran
Alex Reynolds
tran is a UIView page ,dynaimcally i have created...tran.m file inwhich drawRect(which will be called automatically) method is available....how can i call any other methods from view controller..?any solution please?
Mikhail Naimy
You need to instantiate the view controller's view itself (not a subview) as an instance of type `Tran`. This can be done in `-viewDidLoad:` or in Interface Builder.
Alex Reynolds