I have written a class for UITableViewCell called TaskCell and designed a .xib file and connected the File's Owner to the custom class. Then in the View Controller class I want to load the custom design, but it is not showing. This is the code for the View Controller with table view:
ShowTaskViewController.h file:
@interface ShowTaskViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>
{
//Database object
sqlite3 *taskeeDB;
NSString *databasePath;
}
@end
ShowTaskViewController.m file with cell for row at index path method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//Get data for cell
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
Task *taskObj1 = (Task *)[appDelegate.taskArray objectAtIndex:indexPath.row];
NSString *sName = [[NSString alloc] initWithFormat:@"%@",taskObj1.name];
NSString *sLoc = [[NSString alloc] initWithFormat:@"%@",taskObj1.location];
NSString *sTime = [[NSString alloc] initWithFormat:@"%@",taskObj1.time];
NSString *sDate = [[NSString alloc] initWithFormat:@"%@",taskObj1.date];
//Configure cell if null
if (cell == nil) {
//I have written a custom init method to take parameters and assign label text values
cell = [[TaskCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier name:sName location:sLoc time:sTime date:sDate];
}
return cell;
}
If cell is null from dequeue cell list, I am assigning new cell objects where TaskCell is the custom UITableViewCell class. Am I doing the correct process?
Show I try to create the cells as following?
if (cell == nil){
NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"TaskCell" owner:self options:nil];
for (id currentObjects in objects ) {
if ([currentObjects isKindOfClass:[UITableViewCell class]]) {
cell = (TaskCell*) currentObjects;
break;
}
}
}