ViewFactory iphone
Has anyone success开发者_StackOverflow中文版fully used this class to load custom tableViewCells. I have tried to create a singleton of the viewFactory class and load the cells using the shared instance but I get the following error...
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[ViewFactory sharedMyClassName]: unrecognized selector sent to class 0x32a24'
I am using this macro to create the singleton, and following the tutorial here Anyone had any experience with this before? I realise this may be a longshot but if anyone has ever used it then please let me know.
Many thanks
Jules
The only reason that ViewFactory class is a singleton is so that you can access it globally. It would be trivial to take the bit of code in ViewFactory that does useful work and incorporate it into your own table view controller subclass. That would eliminate the singleton, make it easier to use separate nibs for each table, and (IMO) make your code simpler.
Another approach that works well is to put each type of cell in its own nib and use -loadNibNamed:owner:options: to load the cells as needed. The technique is described in Loading Custom Table-View Cells From Nib Files. It's not difficult, and although the example in that section uses only one type of custom cell it's easy to extrapolate to multiple custom cells.
The define
creates a method called sharedViewFactory
and not sharedMyClassName
. It depends on the class name you pass to it. shared
is prepended to the class name. So all ##classname
will be replaced by ViewFactory
.
精彩评论