Cocoa/iPad Inserting new view-what am I doing wrong

Sorry for wanting to ask a simple question.

I have my initial view loaded in the main view controller (TestViewController). The plan is to replace that view with the view from another controller (PageOneViewController). Both views live in the same Nib but are linked to outlets in their respective controllers.

When it comes to running the program, I press the button, the view disappears but nothing replaces it. I must have misunderstood something. By my understanding, it should work. What am I doing wrong?

@class PageOneViewController; @interface TestViewController : UIViewController { } - (void) addPageOne; - (IBAction) pressButton:(id)sender; @end


#import "TestViewController.h" #import "PageOneViewController.h" @implementation TestViewController - (IBAction)pressButton:(id)sender { [self addPageOne]; } - (void) addPageOne { PageOneViewController *pageOne = [PageOneViewController alloc]; [self.view removeFromSuperview]; [self.view insertSubview:pageOne.view atIndex:0]; [pageOne release]; } - (void)dealloc {...


@interface PageOneViewController : UIViewController { IBOutlet UIView *view; } @property (nonatomic, retain) UIView *view; @end


#import "PageOneViewController.h" @implementation PageOneViewController @synthesize view; @end

-------------Problems Reply------------

Calling removeFromSuperview causes the first view to no longer be displayed. Then you add the second view on top of the first view, but since view 1 still isn't being displayed the user can't see either one. You should either keep the first view visible and just cover it up with the second view, or, preferably, have a blank superview that contains either view1 or view2 as a subview depending on which one the program needs.

Category:cocoa touch Views:0 Time:2011-05-09

Related post

  • cocoa iphone load modal view without seeing it 2010-01-08

    Is there a way to load a view modally without seeing it? I need to access methods on the modal view controller which in turn set properties of UI components in a XIB. I want to set those properties, but I don't want to see the view right away. I want

  • How to insert and view images from oracle using jsf 2011-06-03

    Can anyone please give me some code example or link of article explaining that how can i insert and view images to/from oracle using jsf? Thanks in advance. --------------Solutions------------- Have a look at these two tutorials: Uploading files with

  • Problem with Dropbox iPad login modal view controller 2011-07-12

    I have a problem with the Dropbox iPad login modal view controller: sometimes you can't write in the password textfield; you can select it and the keyboard appears, but you can't write. A workaround is to press login, it says you haven't entered the

  • Cocoa: getting a Table View cell to send action messages 2010-03-28

    I'm really having trouble getting a Cocoa Table View cell to send action messages. At the most basic level, in IB there is an action assigned for the NSTextViewCell object, and after editing and pressing Return nothing happens. So I have an IBOutlet

  • SplitView in iPad - Maintain two views without popover 2010-04-26

    In a switch view mode in iPad, is it possible to maintain the two views in landscape mode and also in portrait mode without having to use the popover?(Maybe just adjust the width of each views in portrait, instead of the popover) How would I do that?

  • iPad/iPhone duplicate view and resize? 2010-04-27

    I'm working on an app that is similar to a Presentation application (Keynote/Powerpoint) for the iPad, that will use the VGA adapter to present on screen. However, if the presenter is using the external display for the presentation, I'm wondering if

  • Does iPad support 4096x4096 view? 2010-05-01

    Does iPad support view with a 4096x4096 frame? --------------Solutions------------- You can always try and find out, but for general purposes, I wouldn't go that large without a CATiledLayer. If you don't know about CATiledLayers, basically you need

  • iPad: Changing the view according to the content when orientating (landscape / portrait) 2010-08-11

    I understand that Apple will do a kind of autoresizing thing when iPad / iPhone change orientation and you can set views' autoresizing masks. But what if the views' resizing is not that simple? for example, I have a TableView and each cell has differ

  • iPad landscape modal view incorrectly sized 2010-08-27

    I have a iphone app where I want to present one of the views modally in landscape mode only and have set the code below its view controller. All works fine on the iphone (its intended platform), but when run on the iPad for demonstration, the left ha

  • ipad full screen views with orientation 2010-09-22

    In Interface Builder, what settings do I change for a view so that it fills the screen regardless of the orientation? I am converting an iPhone app, and the views don't fill the screen unless I set the height and width to 768x1024. But when the ipad

  • iPad - topmost modal view controller won't dismiss when there are multiple 2010-10-21

    I'm working on a dual-iPad/iPhone application. I'm having a problem that is occurring on the iPad only: Root view controller is a UISplitViewController on iPad, UITabBarController on iPhone A modal UIViewController can appear over the root controller

  • MPMediaPickerController on iPad - bottom of view not accepting touch events 2010-10-29

    I'm having some trouble with this Media picker on iPad... I can easily recreate the problem in a fresh View-based application. 1) Create new View-Based application for iPad in XCode 2) Open the source for the View Controller and add the following - (

  • iPad: Two Table Views one Controller 2010-11-26

    In my iPad App I am using a SplitView. In Portrait mode, instead of using the popOver, I have another Table View that´s connected to the same controller that has the info for the View that appears in Landscape. My App works great, but I have an 1 war

  • Android - onDraw not being called in dynamically inserted custom view 2010-12-05

    I have a custom view being dynamically inserted and the onDraw is not being called. I initially made the custom view without the dynamic insertion and it worked fine, however when moving it to my working code base, I cannot get onDraw to get called e

  • Ipad DWG/DXF viewing 2010-12-16

    I have seen applications for iPad that let you view dxf and dwg files. Does anyone know where to get info on how to do this? Are there any available tutorials? I haven't been able to find any. I really need some direction on how to do this. The appli

  • xcode insert a view under a another 2011-01-04

    Hey, I want to be able to reproduce this effect that when clicking on one of the button in the menu, a view or viewController appears under the menu controller before the uitableview just like in the MarioCooks app. I have been trying inserting a sub

  • Insert into view in h2 database 2011-02-17

    edit: I want to add values to a table (paziente) working with a view of that table (viewPaziente) and not directly the table. edit2: Found a stupid mistake in the code, now it does give me an error, but it is not helping: org.h2.jdbc.JdbcSQLException

  • oracle: why cant i insert into view 2011-02-17

    I created a simple view with columns from a single table. When i try to insert values into the table, i get the ORA_01732 error that dml is not legal on this view. I DO have an order by clause in the view definition which I've gathered is not allowed

  • Correct way to insert a view with Backbone.js 2011-02-23

    I have a simple backbone.js app. I want to render a view into the DOM of the HTML page, this view is a detail view for a model. My HTML page already has the DIV element that I want to render the view into. If I try to render my view like this: detail

Copyright (C), All Rights Reserved.

processed in 0.073 (s). 11 q(s)