views:

520

answers:

1

I'm trying to use Apple Core Data Sample code as a basis for my own app. I'm using this code: http://developer.apple.com/iphone/library/samplecode/iPhoneCoreDataRecipes/index.html

I can't work out how that first table View is styled. I want it to be grouped (UITableViewStyleGrouped), but there seems to be no obvious place to tell it how to style the table. The table seems to be created programmatically since there is no UITableView in the xibs.

A: 

In the view controller that handles the table, look for the initWithNibName:bundle: method. Override it so that it contains the following snippet:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)bundle {
    if(self = [super initWithNibName:nibNameOrNil bundle:bundle]) {
        self.tableView.style = UITableViewStyleGrouped;

        // Other custom code here...
    }
}
Tim
well, if I put that snippet in the RecipeListTableViewController.m it gives me an error for the 'self.tableView ..' line: "object cannot be set - either readonly property or no setter found"
cannyboy
Did you declare a `@property` and then `@synthesize` your table view? If you have the ivar, but no property or setter method, then you can't access it through self.
Tim
i did that and it made no difference. Is you can make the first table in this sample code Grouped, please let me know. I have been tearing my hair out for days. http://developer.apple.com/iphone/library/samplecode/iPhoneCoreDataRecipes/index.html
cannyboy
OK this is truly sneaky. Apparently what they do is use IB to initialize the instance of RecipesListTableViewController, which by default initializes the controller with a plain table view (with no option to change later). You'll need to take the link to that controller out of IB entirely and do it all in code (forgetting my original answer, and using UITableViewController's `initWithStyle:` initializer).
Tim
I'll try that, thanks. You would think that Apple would make their sample code more flexible.
cannyboy