0

I have 5 segmented contol segments on navigation bar and the requirement of my app is such that I have to change views in within one segment only. Now I have two UIViews within one xib. I have set an integer flag and depending on that flag, I need to change the views. I am posting this because both the view will have a table view within one xib and they will have different number of rows, different cellForRowAtIndexPath and didSelectRowAtIndexPath. So two questions are - How to select a particular view depending on the flag and How to manage delegate methods of both UIViews as file owner will create issues? If someone suggest to create a separate class with UIViewController, then how to overwrite / replace the view for that particular segment?

Please note that i am not using storyboards. App is based on XIB's only

Mirko Catalano
  • 3,850
  • 2
  • 26
  • 39
Deepak Thakur
  • 3,453
  • 2
  • 37
  • 65

1 Answers1

1

If I understand the question (english not native for me), one of the ways to obtain the necessary data:

  1. you can use NSArray *subviews = [[self view] subviews]; for get collection of all views (collection can include not only UIView objects) in your view controller assigned to XIB;
  2. you can check each object belonging to the class [object isKindOfClass:[UIView class]]; to find needed UIViews;
  3. you can determine UIViews by property tag (can set in XIB); or use some other properties for it.
  4. in found UIView you can again get all subviews [view subviews]; and use [object isKindOfClass:[UITableView class]]; to find needed table;
  5. you can use reference to found UITableView in delegate methods to determine to which table the delegate method is called. For example: in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method you need check tableView
Ruslan Soldatenko
  • 1,718
  • 17
  • 25