user141302
user141302

Reputation:

method of UIView calling from UIViewcontroller problem?

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];

}

Upvotes: 0

Views: 496

Answers (1)

Alex Reynolds
Alex Reynolds

Reputation: 96984

  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

Upvotes: 1

Related Questions