views:

351

answers:

1

Hi all,

I have a class A which is a subclass of uitableviewcontroller and one more class B which actually displays my tableview with its content is a subclass of A.

There's an xml parser which parses my xml and stores the content in an nsmutablearray of application delegate. Now, I fetch this delegate array into a local nsmutablearray in class B to minimise the communication between the two classes i.e. delegate and class B and display that.

After certain condition is met in class A, I'm calling xml parser to refill the delegate array and I'm calling class B's tableview reload method. The problem is when I call the tableview's reload data, class B's delegate methods are called. But before that I need to grab this delegate array in local array in class B. How shall I do that?

Can anybody please help?

Thanx in advance.

A: 

Suggest that you post a notification from your xmlParser when it has updated the array. Object B (instance of Class B) can register for the notification. Upon receiving the notification Object B can reload the array before calling [[self tableView] reloadData] in the implementation of Class B.

falconcreek
Can I access subclass' properties from superclass? If yes, how?
neha
Also, can I send out notification in superclass and catch it in subclass?
neha
For any object to access properties of another you need to send a message from one object to the other. There are many ways to obtain a reference of the receiving object by navigating the relationships between objects. You are mixing up important concepts of inheritance (is a) and composition (has a). A common scenario is for object A (instance of ClassA) to create object B (instance of ClassB) and keep a reference to B by setting a property of A to B. A can send messages to B. If ClassB subclasses ClassA, unless a property of B is set to A, (eg delegate), B cannot send a message to A.
falconcreek
Google "nsnotificationcenter tutorial". Notifications are used for sending messages between objects. This is a very powerful mechanism that allows objects to collaborate without having to keep references to each other. The sender of the `NSNotification` can be interrogated by the receiver. In addition, the `userInfo` property `NSNotfication` should contain information needed by the receiver to complete it's task.
falconcreek
Thanx falconcreek.. It helped..
neha