Customize Empty TableView
Hey guys, I'm having an interesting issue, where I want to have a customized table view with rounded corners and a specific background, etc... This works fine, but everything is being set up in cellForRowAtIndexPath. This means that if my table view is empty, this method doesn'开发者_运维百科t get called, and I get this ugly, blank table view showing up.
I can't do the modifications in viewDidAppear, because the tableView gets declared in its methods such as the one mentioned earlier. Any ideas?
Thanks in advance!
Sounds like you just need to find the right spot to initialize your table view, and it's not in cellForRowAtIndexPath, for the reasons you mentioned. Assuming you've created your UITableView in a xib file, you can create an outlet in your source code (see below), and in InterfaceBuilder either make an instance of your controller in the xib file, or use an existing instance (like File's Owner, maybe). In IB, connect that outlet to the table with control-click-drag. When the xib is loaded, UIKit will fill in the pointer to your table view, which you can then go nuts with during viewDidLoad. Does that solve your problem?
@interface MyController : UIViewController<UITableViewDelegate,UITableViewDataSource>
{
UITableView * myTable;
}
@property (nonatomic,assign) IBOutlet UITableView * myTableView;
@end
...
@implementation MyController
@synthesize myTableView;
-(void)viewDidLoad
{
// do some crazy initialization with self.myTableView!
}
@end
精彩评论