xmartlabs / XLMailBoxContainer

Custom container view controller ala MailBox app.
MIT License
89 stars 15 forks source link

How to display custom UITableView with custom UITableViewCell as ChildViewController #6

Closed robertavram-md closed 9 years ago

robertavram-md commented 10 years ago

I'm trying to incorporate XLMailBox, Custom ViewController as a parent viewController that can switch between different childViewController using a TabBar.

I'm loading a Custom UITableViewController called SwipeTableViewController as a childViewController within a parentviewController I use this code to load the ParentViewController in AppDelegate:

@implementation SwipeTableAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
SwipeTableViewController * child_1 = [[SwipeTableViewController alloc] initWithStyle:UITableViewStylePlain];

NSArray * childViewControllers = @[child_1];
XLSwipeContainerController * containerController = [[XLSwipeContainerController alloc] initWithViewControllers:childViewControllers];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:containerController];

return YES;

}

The SwipeTableViewController.m loads the table view as follows:

- (void)viewDidLoad
{

    [super viewDidLoad];
    patternImages = [NSMutableArray arrayWithObjects:@"neon-autumn.gif", @"alchemy.jpg", @"white-wood.jpg", @"green-goblin.png", @"subway-lines.png", @"canvas-orange.jpg", @"kiwis.png", @"cuadros.png", @"hodgepodge.png", @"naranjas.png", @"bunting-flag.png", nil];
    self.title = @"Rounds";
    _patients = [RND_PatientDB loadScaryBugDocs];
   [self.tableView registerClass:[CustomTableViewCell class] forCellReuseIdentifier:@"Cell"];
NSLog(@"FirstViewController - viewDidLoad");

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
                                              initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
                                              target:self action:@selector(addTapped:)];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

       static NSString *cellIdentifier = @"Cell";

    CustomTableViewCell *cell = (CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

    RND_Patient *patients = [self.patients objectAtIndex:indexPath.row];

    cell.patternImageView.image = [UIImage imageNamed:[patternImages objectAtIndex:indexPath.row]];
    cell.patternLabel.text = patients.data.ptName;
    cell.ptDesc.text = patients.data.ptDesc;
    cell.ptNumber.text = patients.data.ptNumber;

    if (patients.data.completed == 1){
        cell.backgroundColor = [UIColor greenColor];
    }
    return cell;
}

It then configures the cell using the CustomTableViewCell class and populates with data from RND_Patients mutablearray which it loads initially in the ViewDidLoad. Now my problem is that when I load the SwipeTableViewController as a childViewController, the cells are empty and are not populated with data, although according to NSLog the data was loaded succesfully.

When I load directly the SwipeTableViewController as part of the RootViewController without using the XLMailBox custom navigation controller, the table view loads just fine and has the appropriate cells and the appropriate data. But whenever I load it as a childviewcontroller of XLSwipeNavigationController, it does not show any data. I know the data source is loaded correctly, because if I set cell.textLabel = patients.data.ptName; it loads the cell textLabel correctly. The problem is I have a custom cell with three different kind of labels, and when I set those labels to the data in my NSMutableArray they do not show up. This leads me to believe that the UITableView is loaded as default and my custom UITableView and CustomTableViewCell are not loaded at all.

I do not understand the discrepancy between these two views. All my code seems correct, but in my first example, the CustomTableViewCell does not load and in the second it loads. Any ideas on how can I fix this?

mtnbarreto commented 10 years ago

@withinthemind please see the new examples in master branch. Hope it helps.