0

So I have a question about views on iPhone. I have an app based on the Tab Bar template in XCode. One of the tab views is a TableView. In that table view, when a user selects one of the cells, I want it to load a view that shows more details about this.

Right now, I have:

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

    SportsAppDelegate *appDelegate = (SportsAppDelegate *)[[UIApplication sharedApplication] delegate];


    // Deselect
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];

//Process which one, sets an index

    //Show detail
    SportsGameView *detail = [[SportsGameView alloc] init];
    [detail setMe:index];  //sets the index that tells it which one

    [appDelegate.window insertSubview:detail.view atIndex:0];
    [self.view removeFromSuperview];
    [detail release];
}

Within the SportsGameView (the one I'm trying to load on top), I have setMe defined to initalize a bunch of UILabels with these.

I can confirm it gets these, but somehow, it doesn't actually show up. I suspect it has something to do with my .xib. I defined IBOutlets in SportsGameView as I normally would, and hooked them up in Interface Builder.

Anyone know why?

Sorry if this was a bit confusing.

Thanks!

Kevin
  • 215
  • 4
  • 14
  • is SportsGameView a subclass of UIView? Or it is actually a subclass of UIViewController? – Firoze Lafeer Dec 04 '10 at 18:45
  • It's a subclass of UIViewController, but nevermind guys, I figured it out! I can't put it into init because it wouldn't have actually made anything yet. – Kevin Dec 04 '10 at 18:50
  • OK, great. But if you are using UIViewControllers anyway, you'll find it much easier to use a UINavigationController for this or at the very least use pushModalViewController instead of doing the view swapping by hand. – Firoze Lafeer Dec 04 '10 at 19:05
  • Yeah I think I'll do that. Thanks. – Kevin Dec 04 '10 at 19:10

1 Answers1

1

You probably don't want to add the view with insertSubview:... atIndex:0, which will put it "below" all other subviews.

If you want to put it on top, just use addSubview:.

Eiko
  • 25,601
  • 15
  • 56
  • 71
  • Well, you currently put it below *everything*... You should keep your view hierarchy tidy and add it to the proper superview. Maybe a navigation controller inbetween would be convenient. I feel as a direct subview of the window it's misplaced. – Eiko Dec 04 '10 at 19:17