I'm wondering how this:
could be done programmatically? Is it just setting the uitableview datasource and delegate to the FadingTableView
class? What exactly is going on by setting the custom class in IB?
Thanks.
Here you are telling IB that the table view instance is actually the instance of FadingTableView
.
and if you want to create this table view programmatically then use these line
FadingTableView *tableView = [[FadingTableView alloc] init.....];
Why you set that class in IB is because the IB has inbuilt objects thus UITableView
but you want your table view which is not present in the IB thus you put your class name there so that it will create instace of FadingTableView
instead of UITableView
.
And No it's not used for connecting datasource or delegate.
Please elaborate on your question as it does not signify it's purpose..I think you are asking the deifference between connecting the datasource and delegates via xib and declaring it programmatically via a class.There is not much of a difference between them but logically if you see IBAction and IBOutlet are just the identifiers to let the compiler know that the object has been defined via interface builder(now integrated with xcode in later versions of xCode).IBAction is defined to void while IBOutlet is just defined.Apple's definition is as:-
#ifndef IBOutlet
#define IBOutlet
#endif
#ifndef
IBAction #define
IBAction void
#endif
Both act as identifiers for compiler that's all.It just tells the compiler that certain methods are defined via interface builder.
What this does is using a subclass of UITableView (apparently) that you have provided in your source code and instantiating it when the nib is loaded. IT does not mean datasource
and delegate
are connected.
To do the same thing in code you would have to remove the TableView from the xib file and create it eg in viewDidLoad
of the ViewController representing that xib file using [[FadingTableView alloc] init…]
, setting the frame
, appearance, delegate
, datasource
and all other attributes manually.
You can use object_setClass(tableView, [CustomClass class]);
and must include #include <objc/runtime.h>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.