views:

333

answers:

1

hello all ,

I have a question concerning UITableviews , the stack and removing components or possibly hiding components on the stack. first I have a function which adds a component (a button );

-(void)addComponent
{
[self.navigationController.view addSubview:playButton];
}

I call this function in my

didSelectRowAtindexPath

So far , so good.

Now comes the "fun" part.
I have another function which is attached to a barbuttonitem

which pushes a next controller on the stack

-(void)lastView:(id)sender
{
 selectedRow = [self.tableView indexPathForSelectedRow];

NSUInteger row = selectedRow.row;

NSUInteger section = selectedRow.section;

[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section] animated:YES scrollPosition:UITableViewScrollPositionBottom];

[self tableView:[self tableView] didSelectRowAtIndexPath:selectedRow];

NSDictionary *dictionary = [self.tableDataSource objectAtIndex:selectedRow.row];

//Get the children of the present item.

NSArray *Children = [dictionary objectForKey:@"Children"];

rvController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];

//Increment the Current View

rvController.CurrentLevel += 1;

//Push the new table view on the stack

[self.navigationController pushViewController:rvController animated:NO];

rvController.tableDataSource = Children;

[rvController release];

}

}

I wish to remove the playButton from the screen , but unfortunately removeFromSuperView doesn't work. I'm guessing it has something to do with the pushing of a new rvController on the stack because when I do this ,it does remove my button perfectly.

Does anyone have a clue as to how I can make sure the button is removed from ALL views on the stack and not just the "current" one as it seems.

edit:

Here is another "funny" part if I put some bogus code here ( but it will push another viewcontroller ) like this :

-(void)lastView:(UITableview *)tableView selectingRow:(NSIndexPath *)indexPath
   {

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

    //Get the children of the present item.

    NSArray *Children = [dictionary objectForKey:@"Children"];

    rvController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];

    //Increment the Current View

    rvController.CurrentLevel += 1;

    //Push the new table view on the stack

    [self.navigationController pushViewController:rvController animated:NO];

    rvController.tableDataSource = Children;

    [rvController release];

    }

    }

Then it seems to work. Though I'm not really sure but it does "look" like it's working.

A: 

Ok interesting .. it seems when I write my function like this .. all is good and well.

selectedRow = [self.tableView indexPathForSelectedRow];

NSDictionary *dictionary = [self.tableDataSource objectAtIndex:selectedRow.row];

//Get the children of the present item.

NSArray *Children = [dictionary objectForKey:@"Children"];

rvController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];

//Increment the Current View

rvController.CurrentLevel += 1;

//Set the title;

rvController.CurrentTitle = [dictionary objectForKey:@"Title"];

//Push the new table view on the stack

[self.navigationController pushViewController:rvController animated:YES];

rvController.tableDataSource = Children;

[rvController release];

mmm but I'm still not completely satisfied however this will have to do for now.