views:

25

answers:

0

Hi, I have an app with two UITableViews on two separate views. Each table view cell data is loaded from a different plist files. The table views load fine but one works correctly but the other seems to combine the two plists which is weird.

Here is How I bring in the plist data

Table 1

- (void)viewDidLoad {
[super viewDidLoad];

NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *DataPath = [Path stringByAppendingPathComponent:@"MyNavAData.plist"];
NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath];
self.data = tempDict;
[tempDict release];


if(CurrentLevel == 0) {

    //Initialize our table data source
    NSArray *tempArray = [[NSArray alloc] init];
    self.tableDataSource = tempArray;
    [tempArray release];

    SecondViewController *AppDelegate = (SecondViewController *) [[UIApplication sharedApplication] delegate];
    self.tableDataSource = [AppDelegate.data objectForKey:@"Rows"];

    self.navigationItem.title = @"Yoga";
}

  else
    self.navigationItem.title = CurrentTitle;
    }

This one works as it should.

Table 2

- (void)viewDidLoad {
[super viewDidLoad];
//[self setDataSourceAndDelegate];

NSString *Paths = [[NSBundle mainBundle] bundlePath];
NSString *DataPaths = [Paths stringByAppendingPathComponent:@"StrongD.plist"];
NSDictionary *tempDicts = [[NSDictionary alloc] initWithContentsOfFile:DataPaths];
self.data = tempDicts;
[tempDicts release];


if(CurrentLevels == 0) {


    NSArray *tempArrays = [[NSArray alloc] init];
    self.tableDataSources = tempArrays;
    [tempArrays release];

         ThirdViewController *AppDelegates = (ThirdViewController *)[[UIApplication sharedApplication] delegate];
    self.tableDataSources = [AppDelegates.data objectForKey:@"Rows"];

    self.navigationItem.title = @"3rd View Strength";
  }

else
    self.navigationItem.title = CurrentTitles;
       }

I use a case statement in each view controller implementation file to navigate the drill down and load a view at the end. This seems to work but the second table takes the drill down cell data from the first plist and then loads final view from the other plist.

Do I have to some how unload one file before I load the other? I have no clue how to do that. Any help would be greatly appreciated. Thanks Dave Fletcher

Thanks for looking at it. Here it is

// Customize the number of sections in the table view.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; }

// Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // return [strongArray count]; return [self.tableDataSources count]; }

// Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"aCell";

UITableViewCell *acell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (acell == nil) {
    acell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}


NSDictionary *dictionary = [self.tableDataSources objectAtIndex:indexPath.row];

acell.textLabel.text = [dictionary objectForKey:@"Title"];
acell.textLabel.font = [UIFont boldSystemFontOfSize:14];
//cell.textLabel.textColor = [UIColor blueColor];
[[acell imageView] setImage:[UIImage imageNamed:[dictionary objectForKey:@"Pic"]]];

return acell;

}

// Override to support conditional editing of the table view. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

 [tableView deselectRowAtIndexPath:indexPath animated:YES];

// Get Dictionary of the selected data source
NSDictionary *dictionary = [self.tableDataSources objectAtIndex:indexPath.row];

// Get the children of the present Item
NSArray *Children = [dictionary objectForKey:@"Children"];

if([Children count] == 0) {

    NSInteger ViewNumber = [[dictionary objectForKey:@"View"] integerValue];
    switch (ViewNumber) {


        case 1: 
        {
            ThirdViewController *tvc = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:[NSBundle mainBundle]];

            // Switch the view here
            //rvc.view = tbController.view;
            [self.navigationController pushViewController:tvc animated:YES];
            self.navigationItem.title = [dictionary objectForKey:@"Title"];
            [tvc release];

        }

            break;


        case 2:
        {
            ChestFlyDB *chestF = [[ChestFlyDB alloc] initWithNibName:@"ChestFlyDB" bundle:[NSBundle mainBundle]];
            [self.navigationController pushViewController:chestF animated:YES];
            [chestF release];
        }
            break;

        case 4:
        {

            PressBarBnch *pressBarBnch = [[PressBarBnch alloc] initWithNibName:@"PressBarBnch" bundle:[NSBundle mainBundle]];
            [self.navigationController pushViewController:pressBarBnch animated:YES];
            [pressBarBnch release];
        }
            break;           

        case 5:
        {


            ChestPressB *chestPressB = [[ChestPressB alloc] initWithNibName:@"ChestPressB" bundle:[NSBundle mainBundle]];
            [self.navigationController pushViewController:chestPressB animated:YES];
            [chestPressB release];
        }
            break;                      
        case 6:
        {


            PushUpBegin *PushUpBeg = [[PushUpBegin alloc] initWithNibName:@"PushUpBegin" bundle:[NSBundle mainBundle]];
            [self.navigationController pushViewController:PushUpBeg animated:YES];
            [PushUpBeg release];
        }
            break;      


        case 7: 
        { 
            PushUpTraditional *PushUpTrad = [[PushUpTraditional alloc] initWithNibName:@"PushUpTraditional" bundle:[NSBundle mainBundle]];
            [self.navigationController pushViewController:PushUpTrad animated:YES];
            [PushUpTrad release];
        }
            break;      

        case 8:
        {
            pushUpAdvanced *pushUpAdv = [[pushUpAdvanced alloc] initWithNibName:@"pushUpAdvanced" bundle:[NSBundle mainBundle]];
            [self.navigationController pushViewController:pushUpAdv animated:YES];
            [pushUpAdv release];
        }
            break;          
            /*       


        default: {
            ThirdViewController *tvController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:[NSBundle mainBundle]];
            [tvController release];

        }
            break;

    }

}
else {

    // Prepare to tableview
    ThirdViewController *tvController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:[NSBundle mainBundle]];

    // Increment the current View

    tvController.CurrentLevels += 1;

    // Set the title

    tvController.CurrentTitles = [dictionary objectForKey:@"Title"];

    // Push the new table view on the stack
    [self.navigationController pushViewController:tvController animated:YES];

    tvController.tableDataSources = Children;

    [tvController release];

}

}