0

I have a class A with textField1, class B with textField2.

i want to use textField1 and textField2 in class C. What i have to import or what i have to do. I think i am straggling with importing files. i.e. #include or something

Thanks for reply in advance.

Mann
  • 5,477
  • 6
  • 45
  • 57
  • See this thread: http://stackoverflow.com/questions/4192203/objective-c-multiple-inheritance – corretge Aug 03 '11 at 11:18
  • do you really need inheritance here or you just need to access textField1 and textField2 from your class C? – Maggie Aug 03 '11 at 11:20
  • @Maggie i need to access values in textField1 and textField2 from both classes in my class C label. Nothing else. – Mann Aug 03 '11 at 11:23
  • use composition instead. http://www.artima.com/designtechniques/compoinhP.html – Valentin Jacquemin Aug 03 '11 at 12:14
  • Can anyone suggest me how can i use composition to access values in the textField1 and textField2 in class C. – Mann Aug 03 '11 at 13:29

2 Answers2

2

Objective does not support multiple inheritance. You can only inherit from one class, you could use a protocol to make the class match class B.

rckoenes
  • 69,092
  • 8
  • 134
  • 166
  • Ok that is fine. But how can i use protocol to access textField value of class B in class C. Protocol is used to access methods – Mann Aug 03 '11 at 11:19
0

Yes, you have to import both class A and class B in class C, and then access textField1 and textField2. Import syntax is #import "classA.h"

Maggie
  • 7,823
  • 7
  • 45
  • 66
  • I have tried this mate. But my class C is subclass of class A only, for example the interface of class C says @impliment class C: class A{..}. After importing it does not access textField of class B. – Mann Aug 03 '11 at 11:21
  • ok, you didn't state it that way in your question. use @corretge's answer then. – Maggie Aug 03 '11 at 11:23
  • In that post he deals with methods. i really dont want to do anything with methods. I need to simply access textField VAlues. thats it – Mann Aug 03 '11 at 11:28
  • no mate it is not working. I have to access textField values not any method from classA or classB in classC. – Mann Aug 03 '11 at 11:47
  • can't you keep a reference of class B in your class C? – Maggie Aug 03 '11 at 11:54
  • I can use class B's textField in class C with creating object of class B in C and accessing like b.textField. It shows no error. But it does not show textField value even – Mann Aug 03 '11 at 12:50