-2

I want to break my code into 3 files and them up via addsubview. For ex. i have a masterview, mastreview contains a currentView. CurrentView contains 1 webview and 1 tableview. Now, i have written all code in one file and it works like a charm. But i want to make it abstract and loosely coupled . So i need a separate file ex. webviewController to implement its delegate and function related to it AND tableviewController to implement its delegate and functions related to it. And add both by addsubview, alloc init in masterview file.

I did it my way,though i was able to addsubview on CurrentView, the problem was my delegate functions are not working properly. Also, i am confused about tableviewController should inherit UIViewController or UIView or UITableView.

it would be good if anyone can guide or send some link related to it, any example...???

Sumitiscreative
  • 647
  • 3
  • 10
  • 24
  • Did you make a strong/retained references for the assigned subviews delegate objects at masterview ? – A-Live Sep 07 '12 at 08:34
  • No.... i just did alloc init and add asa subview – Sumitiscreative Sep 07 '12 at 08:37
  • I mean the view controllers for the subviews – A-Live Sep 07 '12 at 08:44
  • hi sorry for late reply.....yes now its working...i tried doing by both retain/assign and it worked both the ways but i don't it should be retain or assign. According to theory it should be assign to avoid retain cycle, but somehow as i remember it didnt work with assign properly...what to use ? retain/assign??? – Sumitiscreative Sep 25 '12 at 05:42

1 Answers1

0

Actually you should have the app crashing if the delegates are not retained somewhere.

If you do link the object with view controller to be it's delegate at Interface Builder, the view controller will be destroyed after it's outlets so you don't care. If you are creating separate class for the delegate, you should care about it's lifecycle, standard classes do not retain their delegates so you have to retain it on the same level where you are retaining the delegated object. Like if you are creating a UITableView subview and you have MyTVDelegate class, you should create the delegate instance, assign it to tableView.delegate and retain as viewController var so that viewController will dealloc both subviews and their delegates when needed.

For the second question, UITableviewController inherits UIViewController as you can see at header files (command+click on UITableviewController), and UITableView inherits UIView. Every viewcontroller should have the root view of UIView and I believe UITableviewController has UITableView as it's root view.

A-Live
  • 8,904
  • 2
  • 39
  • 74