I’m a little confused with something. I’m trying to create a custom cell and I want to use the interface builder way.
The normal way I create a table is to have the table as:
.h
@interface AssessList : UIViewController {
IBOutlet UITableView *tblAssessList;
}
@property(nonatomic, retain) UITableView *tblAssessList;
@end
.m
- (NSInteger)
numberOfSectionsInTableView:(UITableView *)tableView {
return groupArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return totalArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = @"I am the text....";
return cell;
}
Now i’ve created a new class for the cell and I think I understand how to put that in. But can I leave the .h as
@interface AssessList : UIViewController
or does the class/nib with the full table on it have to be a UITableViewController?
Tom
No. A
UITableViewControlleris just a convenienceUIViewControllersubclass which has aUITableViewand is already setup as its delegate/datasource (it is declared as conforming to theUITableViewDelegateandUITableViewDatasourceprotocols), it also has pre-filled method implementations for these protocols in the template implementation file which Xcode generates for you. You can just as well do all of this yourself, I often do.You should however make an IBOutlet for your UITableViewCell so that you can load it from the nib file (see the Loading Custom Table-View Cells From Nib Files in the Table View Programming Guide).