views:

1172

answers:

1

I'm a bit confused all as to why the belowSubview does not work.

I'm adding some (subviews) to my navigationController and all of that works well.

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

... 
...

    [self.navigationController.view addSubview:ImageView];
    [self.navigationController.view addSubview:toolbar];

add some point in my app I wish to add another toolbar or image above my toolbar.

so let's say I'm doing something like this

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    {
    ...
    ...

        [self.navigationController.view insertSubview:NewImageView aboveSubview:toolbar];
//crucial of course [edit]
            rvController = [RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle] mainBundle];
rvController.CurrentLevel += 1;
rvController.CurrentTitle = [dictionary objectForKey:@"Title"];
[self.navigationController pushViewController:rvController animated:YES];
rvController.tableDataSource = Children;
[rvController release];

However this doesn't work.. Does anyone know what I'm doing wrong here ... Should I have used something else instead of addSubview or is the problem somewhere else?

A: 

From what you have posted, it looks like that should work.

There are a few other issues however. First it is convention that varibales that represent instances of objects start with lowercase. So ImageView and NewImageView should be imageView and newImageView.

I would make sure that in your tableView:didSelectRowAtIndexPath: method newImageView and toolbar are both valid. Are they in your header file?

Try this and see where is errors out:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
...
...
    NSAssert(self.navigationController.view,@"WTF? self.navigationController.view is nil");
    NSAssert([self.navigationController.view superview],@"WTF? lf.navigationController.view  is not onscreen");
    NSAssert(newImageView,@"WTF? newImageView is nil");
    NSAssert(toolbar,@"WTF? toolbar is nil");
    NSAssert([toolbar superview],@"WTF? toolbar is on in the view");

    [self.navigationController.view insertSubview:newImageView aboveSubview:toolbar];
}
Brad Smith
Thanks for your reaction .. you were right, there is nothing wrong with I just made a slight mistake ;) which you can see in my edit. I pushed a new viewController...
Are you trying to get your new image/toolbar above the toolbar on the original screen, or the new one that appears? or both?
Brad Smith