Add UIView subclass to UIViewController subclass programatically

Hi.
I've been trying to find out how to add a UIView subclass to a UIViewController subclass all in code with no IB.
I've googled and searched forums but nothing seems to work for me.
How would you go about making the most simple app that has an appDelegate, view controller, and a view?
I load the view controller (MainViewController) and anchor it to the window in appDelegate.
Then I make a UIView subclass (MainView) and add the class to mainViewController and create an instance of it.
I import the .h and in the loadView method of the viewController I add this:
[self.view addSubview:mainView];
That doesn't seem to work and I have also tried initializing it like so:
CGRect = screenBounds = [[UIScreen mainScreen] applicationFrame];
CGRect = windowBounds = screenBounds;
windowBounds.origin.y = 0.0;
self.view = [[UIWindow alloc] initWithFrame:screenBounds];
mainView = [[MainView alloc] initWithFrame:windowBounds];
[self.view addSubview:mainView];
All this results in absolutely nothing except for the white background of the view controller to show.
Just to see if it works, I initialized the mainView's background to a greenColor;
Any help would be much appreciated as this is the only thing preventing me from completing an app.

Here are the .m files for a project named AllCode. I started it by removing the nib file from the Window-Based Application template:
// main.m - since there's no nib the app delegate class must be specified here
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"AllCodeAppDelegate");
[pool release];
return retVal;
// AllCodeAppDelegate.m
#import "AllCodeAppDelegate.h"
#import "MyViewController.h"
@implementation AllCodeAppDelegate
@synthesize window;
@synthesize myViewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
CGRect frame = [[UIScreen mainScreen] applicationFrame];
UIWindow *aWindow = [[UIWindow alloc] initWithFrame:frame];
self.window = aWindow;
[aWindow release];
MyViewController *aViewController = [[MyViewController alloc] init];
self.myViewController = aViewController;
[aViewController release];
[window addSubview:myViewController.view];
[window makeKeyAndVisible];
- (void)dealloc {
[window release];
[myViewController release];
[super dealloc];
@end
// MyViewController.m
#import "MyViewController.h"
#import "MyView.h"
@implementation MyViewController
@synthesize label;
- (void)loadView {
CGRect frame = [[UIScreen mainScreen] bounds];
self.view = [[MyView alloc] initWithFrame:frame];
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor lightGrayColor];
CGRect rect = CGRectMake(100, 210, 120, 21);
UILabel *aLabel = [[UILabel alloc] initWithFrame:rect];
self.label = aLabel;
[aLabel release];
label.text = @"Hello World!";
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
[self.view addSubview:label];
- (void)dealloc {
[label release];
[super dealloc];
@end
Edit Info.plist to remove the Main nib file base name--i.e. just delete the default name to leave that field blank--and you should be good to go.

Similar Messages

  • Connect a UIView with a UIViewController

    How can I connect a UIView subclass with a UIViewController subclass with code? I know how associate a nib file with a UIViewController, but it would be nice not having to create nib files for all my view controller classes, and just create everything with code instead.

    in your UIViewController's viewDidLoad event, wouldn't you initialize your UIView class and assign that object to the view property of your view controller?
    -MrB

  • How to add ShowDetailItem to PanelAccordion at runtime (Programatically)?

    Hi,
    I am creating a PanelAccordion in a popup programatically.
    I have add & delete CommandButtons in popup, using which i am trying to add and delete ShowDetailItem from PanelAccordian.
    I tried to call a ActionListener on CommandButton to add showDetailItem to Accordion at runtime. But its not working.
    This is how i am trying to implement:
    RichPanelAccordion contactsContainer = new RichPanelAccordion();
    public void BuildUI(){
            RichPanelGroupLayout parentContainer = new RichPanelGroupLayout();
           // Adding button
            RichCommandButton addContact = new RichCommandButton();
            addContact.setText("Add Contact");
            MethodExpression addEx =
              adfUtils.resloveMethod("#{pageFlowScope.contactsBean.addNewContact}",
                            Object.class, new Class[] { });
            addContact.setActionExpression(addEx);
            // Adding Accordion
            RichPanelAccordion contactsContainer = new RichPanelAccordion();
            contactsContainer.setId("contactsContainer");
            parentContainer.getChildren().add(addContact);
            parentContainer.getChildren().add(addContact);
        public void addNewContact() {
          RichShowDetailItem contact = new RichShowDetailItem();
          contact.setText("New Contact");
          contactsContainer.getChildren().add(contact);
          System.out.println("::: Add Contact :::" +  contactsContainer.getChildren().size());
          RequestContext.getCurrentInstance().addPartialTarget(contactsContainer);
        }While creation of PanelAccordion, i added couple of ShowDetailItems to it.
    After calling addNewContactMethod, its not getting updated with new one.
    I tried to get the children of panel accordion while adding. It is showing zero. To access this PanelAccordion in outside, i initialized panelAccordion globally. I think thats y its showing children zero.
    How to achieve this requirement? Looking for some ideas.
    Thanks in Advance.
    Thoom..

    Hi Thoom,
    First of all, debug your code, and try to pay attention if each request you're doing is creating a new RichPanelAccordion (watching the id of instance). If yes, verify your MB scope (pageFlowScope is better) and test your instance before add:
    public RichPanelAccordion  getContactsContainer(){
    if (contactsContainer  == null)
    contactsContainer = new RichPanelAccordion();
    return  contactsContainer  ;
    Regards,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Constructor in a subclass of UIView?

    I have generated an application based on the Utility App template for Iphone. In my MainView class I have written som initialisation code that isn't called:
    - (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
    NSLog(@"MainView instanse initialised");
    // Initialization code
    NSLog(@"MainView instanse initialised");
    return self;
    None of the log messages appears, how is UIView being initialised?
    Thomas

    init will never be called, because the constructor for UIView is initWithFrame. If you create a UIView-subclass object then you will do so by calling alloc on the class and then initWithFrame on the result of alloc.
    On the other hand, if you are relying on the object coming into existence because it was specified in Interface Builder, then the object isn't, conceptually, being created at all when your program starts. The idea is that Interface Builder created the object, archived it to the NIB file, and your program is now un-archiving it from there.
    Your awakeFromNib method is called after the object has been un-archived from the NIB file. I've tended to use this on the Mac; on the iPhone I've tended to use the UIViewController's viewDidLoad method instead.
    Here is what the documentation has to say on the subject of awakeFromNib:
    +During the instantiation process, each object in the archive is unarchived and then initialized with the method befitting its type. Objects that conform to the NSCoding protocol (including all subclasses of UIView and UIViewController) are initialized using their initWithCoder: method. All objects that do not conform to the NSCoding protocol are initialized using their init method. After all objects have been instantiated and initialized, the nib-loading code reestablishes the outlet and action connections for all of those objects. It then calls the awakeFromNib method of the objects. For more detailed information about the steps followed during the nib-loading process, see Nib Files and Cocoa in Resource Programming Guide.+
    The "Nib Files and Cocoa" article is long and complex and, as far as subclasses of UIView are concerned, untrue.

  • Putting an Extended SubClass on Stage?

    I'm running into the situation where I can't instance a SubClass in the above SuperClass because the SubClass is extending from the SuperClass.
    I get stack overflow. Fair enough, right?
    Well, I want to add this SubClass to the display, and the only way I know how to do that is through addChild(). To addChild() I need to instance the SubClass.
    Has anybody run into this or know what I mean?
    I can't put any visual display instance or events in this subclass because it's currently null and extends is keeping me from doing so. It's great cuz I can share all the goods, but now I'm stuck dancing inside functions because I can't use events on the main "timeline" of the null SubClass.
    If anybody can help, I'm open to any suggestions. I'd really like to be able to free this up instead of relying on public functions in the SubClass to reference SuperClass display objects.

    wherever you're creating instances of your subclass should be where you add it to the displaylist.

  • How to add programatically/dynamically input parameters to a taskflow?

    I have usecase like this -
    I have a taskflow created. But I dont know how many input parameters that I need to define on this taskflow.
    Is there any way, by which I can add input parameters to a taskflow programatically? using a MBean or any APIs are available that will enable to do this?

    When using the task-flow as a region, instead of specifying the parameter individually - you could provide Map as the input parameters with Key being the parameter name and Value being the actual value of the parameter.
    Check this sample:
    http://adfsampleapplications.googlecode.com/svn/trunk/TaskflowParamSampleApp.zip
    Thanks,
    Navaneeth

  • UIView EXC_BAD_ACCESS on super dealloc

    I have a UIView subclass that is causing EXCBADACCESS errors in the dealloc method when calling super dealloc. I have a navigation bar setup with a segmented control as the titleView. It pushes MyViewController when one segment is touched, and pops it when the other is touched (if it was pushed prior). MyViewController handles the touches when it is the visible view controller, and calls the navigation controller's pop method. It is being deallocated when pop is called, then the MyView (which was set to self.view in the VC) is deallocated. MyView seems to try to call removeFromSuperview which is causing the error.
    When I leave "super dealloc" out of the dealloc method of MyView, it doesn't throw the bad access, but XCode shows a warning and makes me worry not everything will be deallocated.
    // MyView.m
    @interface MyView (Private)
    - (void) _setupButtons;
    @end
    @implementation MyView
    - (id) initWithMyMethod {
    if (self = [super init]) {
    [self _setupButtons];
    return self;
    - (void) dealloc {
    [btn release];
    // [super className] prints MyView
    // [self.superview className] prints (null)
    [super dealloc];
    // This line is never reached
    @end
    // MyViewController.m
    @implementation MyViewController
    - (void)loadView {
    MyView *theView = [[MyView alloc] initWithMyMethod];
    self.view = theView;
    [theView release];
    - (void)dealloc {
    [super dealloc];
    - (void) segmentAction:(id)sender {
    // If the other segment is touched
    if( [sender selectedSegmentIndex] == 0 ){
    [(UINavigationController *)self.parentViewController popViewControllerAnimated:YES];
    @end
    Stack trace:
    #0 0x915f4688 in objc_msgSend
    #1 0x30a83885 in -[UIView(Hierarchy) removeFromSuperview]
    #2 0x30a7d2a6 in -[UIView dealloc]
    #3 0x000160b2 in -[MyView dealloc] at MyView.m:43
    Any ideas?

    Bah. You're right. I was using [UIButton buttonWithType:] without ever retaining it, then trying to release it. I still don't understand why it waited until [super dealloc] to deallocate the buttons though.

  • Adding view link programatically

    Hi,
    I have created a view link programatically but dont know how to add it to AM.Can anyone tell me how to add this view link to AM Programatically.
    Thanks,
    Anupama

    Hi,
    I have created a view link programatically but dont know how to add it to AM.Can anyone tell me how to add this view link to AM Programatically.
    Thanks,
    Anupama

  • Grouping multiple views

    This is probably a simple question for someone to answer.
    I want to make a subclass of UIView that effectively just groups a UIButton and a UILabel arranged ina certain layout. I want to do this so I can instantiate this subclass over and over and used the group with a different picture in the UIButton and differet text in the UILabel but maintain a layout and other settings like fonts and colors.
    I went into Xcode and did Add -> New File... -> UIView subclass. The template gave me a class with a bunch of methods (initWithFrame:, drawRect:, dealloc). What would I put into these methods? How do I add the UIButton and UILabel as subviews? How do I create a method that will take in the image and the text for the label so it can draw it with those?

    You add the button, label etc as fields in your class and then initialise them in one of the init or viewDidLoad methods. Read the UIView documentation to see methods available to manage subviews. Create accessor methods for setting the text, image etc. that you can use from other parts of your application.

  • Freely Moving Objects in Xcode

    I am trying to make a simple iphone app and I have so far made two squares and a circle. I have been trying to get the objects to move freely and slowly speed up. Could someone please provide a tutorial on how to do this.
    Thanks ahead of time.

    What you are looking for is this:
    Starting with a UIView subclass, I'll call it View, add the following to the header:
    #import <UIKit/UIKit.h>
    typedef struct
    CGFloat x;
    CGFloat y;
    } Vector2D;
    typedef struct
    Vector2D position;
    Vector2D velocity;
    } Sprite;
    @interface View : UIView {
    Sprite ball;
    @end
    and the implementation:
    #import "View.h"
    #define kBallWidth 25.0
    @implementation View
    - (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
    [UIApplication sharedApplication].statusBarHidden = YES;
    ball.position.x = 200;//**relative to upper left corner for Quartz
    ball.position.y = 300;
    ball.velocity.x = 2.0;
    ball.velocity.y = -5.0;
    //Start rendering timer
    [NSTimer scheduledTimerWithTimeInterval:(1.0 /30.0) target:self selector:@selector(update) userInfo:nil repeats:YES];
    return self;
    -(void)update {
    if(ball.position.x <= self.bounds.origin.x || ball.position.x + kBallWidth >= self.bounds.size.width)
    ball.velocity.x *= -1.0; //negate to reverse direction
    if(ball.position.y <= self.bounds.origin.y || ball.position.y + kBallWidth >= self.bounds.size.height)
    ball.velocity.y *= -1.0; //negate to reverse direction
    //commit to changes
    ball.position.x += ball.velocity.x;
    ball.position.y += ball.velocity.y;
    [self setNeedsDisplay];//trigger the drawRect method
    - (void)drawRect:(CGRect)rect {
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextClearRect(context, rect);
    CGFloat white[4] = {1.00f, 1.00f, 1.00f, 1.0f};
    CGContextSetFillColor(context, white);
    CGContextAddRect(context, CGRectMake(ball.position.x, ball.position.y, kBallWidth, kBallWidth));
    CGContextFillPath(context);
    @end
    As with any game, the hardest part for a beginner is not the physics required to get a ball moving around on the display, it's the graphics API that gives the trouble (in this case, Quartz2D).

  • Adding a file to an already created Archive throws error

    Hello Experts,
    In one of the WLST python scripts, we had a piece of code which was adding a file to an already created archive. Below is the code snippet:
    import zipfile
    try:
    conn='1.properties'
    fileName='/home/pbnagara/temp/Zip1.par'
    myZip = zipfile.ZipFile(fileName, mode='a')
    myZip.write(conn)
    myZip.close()
    except Exception:
    print 'Exception occurred while writing to Zip file: ' + fileName
    --> it makes use of the standard python module [zipfile] to add a file to the archive.
    This code has started failing [for some strange unknown reason] when we upgraded.
    The same script works fine in a standalone mode[using the system's default python packages] but fails only when run within WLST.
    Does WLST package a different set of zipfile libraries? Can anyone point out what might be going wrong here?

    I did get a reply from someone on the jfreechart forum, but need to ask more questions. This was his reply:
    Hi Allyson,
    You are trying to add a (subclass of) JFrame to a JPanel...that won't work, of course, and Java tells you so.
    You need to create a ChartPanel to display your chart. This is a subclass of JComponent, which you can happily add to a JPanel (or any other container).
    Regards,
    Dave Gilbert
    Here is the code for the method:
    private void LineChartFrame() {
    double[][] data = new double[][] {
    { 1.0, 4.0, 3.0, 5.0, 5.0, 7.0, 7.0, 8.0 },
    { 5.0, 7.0, 6.0, 8.0, 4.0, 4.0, 2.0, 1.0 },
    { 4.0, 3.0, 2.0, 3.0, 6.0, 3.0, 4.0, 3.0 }
    DefaultCategoryDataset dataset = new DefaultCategoryDataset(data);
    // set the series names...
    String[] seriesNames = new String[] { "First", "Second", "Third" };
    dataset.setSeriesNames(seriesNames);
    // set the category names...
    String[] categories = new String[] { "Type 1", "Type 2", "Type 3", "Type 4", "Type 5", "Type 6", "Type 7", "Type 8" };
    dataset.setCategories(categories);
    // create the chart...
    chart = ChartFactory.createLineChart(
    "Line Chart Demo 1", // chart title
    "Category", // domain axis label
    "Value", // range axis label
    dataset, // data
    true, // include legend
    true, // tooltips
    false); // urls
    chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
    }And I tried this to add it to my panel:
    jPanel1.add(chartPanel, null);But I get this error:
    java.lang.NullPointerException
    ChartPanel is defined globally in this file.
    jPanel1 is my main panel that I want to add the chart to.
    I am putting my last duke dollar on this in the hopes that someone can help. Thanks.
    Allyson

  • [iPhone] OpenGL IPhone Question

    Greetings, I am new to programming on the iPhone and Objective-C so I hope you will excuse me if I ask a stupid question. I am experienced at Java (having worked with it for 14 years professionally) and I have some background in C and C++ that I have half forgotten but not completely.
    I am trying to learn OpenGL programming on the iPhone and I have encountered a problem. In my test application I want to draw a icosahedron and I am having trouble with several sides completely missing. I was hoping someone could lead me in the right direction. Pasted below are the relevant sections of code based off the template for the OpenGL template.
    It draws a good portion of the icosahedron but there appear to be sides missing and that causes odd things. I have been fiddling with this for hours and im out of ideas. I assume it must be something simple.
    #import <UIKit/UIKit.h>
    #import <OpenGLES/EAGL.h>
    #import <OpenGLES/ES1/gl.h>
    #import <OpenGLES/ES1/glext.h>
    #import "GameBead.h"
    This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.
    The view content is basically an EAGL surface you render your OpenGL scene into.
    Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
    @interface EAGLGameView : UIView {
    @private
    GLint backingWidth;
    GLint backingHeight;
    EAGLContext *context;
    GLuint viewRenderbuffer, viewFramebuffer;
    GLuint depthRenderbuffer;
    GameBead* bead;
    - (void)drawWithRotationX:(GLfloat)rotX Y:(GLfloat)rotY;
    @end
    #import <QuartzCore/QuartzCore.h>
    #import <OpenGLES/EAGLDrawable.h>
    #import "EAGLGameView.h"
    #define USEDEPTHBUFFER 0
    @interface EAGLGameView ()
    @property (nonatomic, retain) EAGLContext *context;
    - (BOOL) createFramebuffer;
    - (void) destroyFramebuffer;
    @end
    @implementation EAGLGameView
    @synthesize context;
    // You must implement this
    + (Class)layerClass {
    return [CAEAGLLayer class];
    //The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:
    - (id)initWithCoder:(NSCoder*)coder {
    bead = [[GameBead alloc] init];
    if ((self = [super initWithCoder:coder])) {
    // Get the layer
    CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
    eaglLayer.opaque = YES;
    eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
    [NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
    context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
    if (!context || ![EAGLContext setCurrentContext:context]) {
    [self release];
    return nil;
    return self;
    - (void)drawWithRotationX:(GLfloat)rotX Y:(GLfloat)rotY {
    [EAGLContext setCurrentContext:context];
    glBindFramebufferOES(GLFRAMEBUFFEROES, viewFramebuffer);
    glViewport(0, 0, backingWidth, backingHeight);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrthof(-2.0f, 2.0f, -3.0f, 3.0f, -2.0f, 2.0f);
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GLCOLOR_BUFFERBIT| GLDEPTH_BUFFERBIT | GLSTENCIL_BUFFERBIT);
    glPushMatrix();
    GLfloat rotZ = 0.0f;
    [bead drawWithRotationX: rotX Y: rotY Z:rotZ];
    glPopMatrix();
    glBindRenderbufferOES(GLRENDERBUFFEROES, viewRenderbuffer);
    [context presentRenderbuffer:GLRENDERBUFFEROES];
    - (void)layoutSubviews {
    [EAGLContext setCurrentContext:context];
    [self destroyFramebuffer];
    [self createFramebuffer];
    [self drawWithRotationX: 0.0f Y:0.0f];
    - (BOOL)createFramebuffer {
    glGenFramebuffersOES(1, &viewFramebuffer);
    glGenRenderbuffersOES(1, &viewRenderbuffer);
    glBindFramebufferOES(GLFRAMEBUFFEROES, viewFramebuffer);
    glBindRenderbufferOES(GLRENDERBUFFEROES, viewRenderbuffer);
    [context renderbufferStorage:GLRENDERBUFFEROES fromDrawable:(CAEAGLLayer*)self.layer];
    glFramebufferRenderbufferOES(GLFRAMEBUFFEROES, GLCOLOR_ATTACHMENT0OES, GLRENDERBUFFEROES, viewRenderbuffer);
    glGetRenderbufferParameterivOES(GLRENDERBUFFEROES, GLRENDERBUFFER_WIDTHOES, &backingWidth);
    glGetRenderbufferParameterivOES(GLRENDERBUFFEROES, GLRENDERBUFFER_HEIGHTOES, &backingHeight);
    if (USEDEPTHBUFFER) {
    glGenRenderbuffersOES(1, &depthRenderbuffer);
    glBindRenderbufferOES(GLRENDERBUFFEROES, depthRenderbuffer);
    glRenderbufferStorageOES(GLRENDERBUFFEROES, GLDEPTH_COMPONENT16OES, backingWidth, backingHeight);
    glFramebufferRenderbufferOES(GLFRAMEBUFFEROES, GLDEPTH_ATTACHMENTOES, GLRENDERBUFFEROES, depthRenderbuffer);
    if(glCheckFramebufferStatusOES(GLFRAMEBUFFEROES) != GLFRAMEBUFFER_COMPLETEOES) {
    NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GLFRAMEBUFFEROES));
    return NO;
    // -- set up the lighting.
    GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat mat_shininess[] = { 50.0 };
    GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
    GLfloat matambdiff[] = { 0.6, 1.0, 0.6, 1.0 };
    glClearColor (0.0, 0.0, 0.0, 0.0);
    glShadeModel (GL_SMOOTH);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
    glMaterialfv(GL_FRONT, GLAMBIENT_ANDDIFFUSE, matambdiff);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GLDEPTHTEST);
    // -- done
    return YES;
    - (void)destroyFramebuffer {
    glDeleteFramebuffersOES(1, &viewFramebuffer);
    viewFramebuffer = 0;
    glDeleteRenderbuffersOES(1, &viewRenderbuffer);
    viewRenderbuffer = 0;
    if(depthRenderbuffer) {
    glDeleteRenderbuffersOES(1, &depthRenderbuffer);
    depthRenderbuffer = 0;
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [touches anyObject];
    CGPoint now = [touch locationInView:self];
    CGPoint old = [touch previousLocationInView:self];
    CGFloat rotX = now.x - old.x * 1.0f;
    CGFloat rotY = now.y - old.y * 1.0f;
    [self drawWithRotationX:rotX Y:rotY];
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    - (void)dealloc {
    if ([EAGLContext currentContext] == context) {
    [EAGLContext setCurrentContext:nil];
    [context release];
    [bead release];
    [super dealloc];
    @end
    #import <OpenGLES/EAGL.h>
    #import <OpenGLES/ES1/gl.h>
    #import <OpenGLES/ES1/glext.h>
    @interface GameBead : NSObject {
    GLfloat vertexData[20 * 3 * 3];
    -(id)init;
    -(void)drawWithRotationX:(GLfloat)xrot Y:(GLfloat)yrot Z:(GLfloat)zrot;
    @end
    #import "GameBead.h"
    @implementation GameBead
    - (id)init {
    // ---- The data that makes up a unit Icosahedron. ----
    // References:
    // http://en.wikipedia.org/wiki/Golden_ratio
    // http://en.wikipedia.org/wiki/Golden_rectangle
    const uint sideCount = 20;
    const GLfloat x = 0.525731112119133606f;
    const GLfloat z = 0.850650808352039932f;
    const GLfloat ico_vertices[12][3] = {
    {-x, 0.0, z}, {x, 0.0, z}, {-x, 0.0, -z}, {x, 0.0, -z},
    {0.0, z, x}, {0.0, z, -x}, {0.0, -z, x}, {0.0, -z, -x},
    {z, x, 0.0}, {-z, x, 0.0}, {z, -x, 0.0}, {-z, -x, 0.0}
    const GLuint ico_triangles[20][3] = {
    {0,4,1}, {0,9,4}, {9,5,4}, {4,5,8}, {4,8,1},
    {8,10,1}, {8,3,10}, {5,3,8}, {5,2,3}, {2,7,3},
    {7,10,3}, {7,6,10}, {7,11,6}, {11,0,6}, {0,1,6},
    {6,1,10}, {9,0,11}, {9,11,2}, {9,2,5}, {7,2,11}
    uint idx, vidx;
    [super init];
    for (idx = 0; idx < sideCount; idx++) {
    for (vidx = 0; vidx < 3; vidx++) {
    vertexData[(idx * 9) + (vidx * 3) + 0] = icovertices[icotriangles[idx][vidx]][0];
    vertexData[(idx * 9) + (vidx * 3) + 1] = icovertices[icotriangles[idx][vidx]][1];
    vertexData[(idx * 9) + (vidx * 3) + 2] = icovertices[icotriangles[idx][vidx]][2];
    return self;
    - (void)drawWithRotationX:(GLfloat)rotX Y:(GLfloat)rotY Z:(GLfloat)rotZ {
    glMatrixMode(GL_MODELVIEW);
    glEnableClientState(GLVERTEXARRAY);
    glVertexPointer(3, GL_FLOAT, 0, vertexData);
    glEnableClientState(GLNORMALARRAY);
    glNormalPointer(GL_FLOAT, 0, vertexData);
    glDrawArrays(GL_TRIANGLES, 0, 180);
    glRotatef(rotX, 0.0f, 1.0f, 0.0f); // x rotation is about y axis
    glRotatef(rotY, 1.0f, 0.0f, 0.0f); // y rotation is about x axis
    glRotatef(rotZ, 0.0f, 0.0f, 1.0f); // z rotation is about z axis
    - (void) normalizeVertex:(GLfloat*)vertex {
    GLfloat d = sqrt((vertex[0]vertex[0])(vertex[0]*vertex[0])(vertex[0]vertex[0]));
    // guarantee that the vector isnt zero length
    if (d == 0.0) {
    NSException* ex = [NSException exceptionWithName:@"Bad Arguments" reason:@"Arguments resulted in a zero length vector." userInfo:nil];
    @throw ex;
    vertex[0] /= d; vertex[1] /= d; vertex[2] /= d;
    - (void)dealloc {
    free(vertexData);
    [super dealloc];
    @end

    hausy wrote:
    have you skype ? we can learn from each other
    Im sorry, I cant give out personal information like that on an open forum. Especially when you arent willing to state your reasons. That would just be stupid.
    -- Robert

  • Launch a splash screen when an iPhone app starts

    Hi, I am trying to make a simple game for the iPhone, and when the app launches, I want a splash screen with instructions to come up. I also want the user to be able to push anywhere on the screen to dismiss it. However, the splash screen doesn't load! I made a new nib file with the splash screen, created a view controller, and a UIView subclass for the screen. Then, I inserted this code into the applicationDidFinishLaunching method of the app delegate:
    - (void)applicationDidFinishLaunching:(UIApplication *)application {
    [window addSubview:[splashViewController view]];
    splashViewIsCurrentView = YES;
    [window makeKeyAndVisible];
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    if(splashViewIsCurrentView) {
    [[splashViewController view] removeFromSuperview];
    [window addSubview:[gameViewController view]];
    splashViewIsCurrentView = NO;
    I forgot to mention, in interface builder, I made the splash view's class as SplashView, and the File's Owner as the SplashViewController. Also, splashViewIsCurrentView is a boolean I made.

    I like the idea behind your use of "splashViewIsCurrentView". I think that may solve my problem.
    I too have a full-screen instruction view pop up over the main input view of the app. The instruction view is added as a subview of the main input view. I want to dismiss the instruction view with a touch. However, in the instruction view view controller, the touch even methods are not fired - even after twiddling with enabling user interaction on the instruction view and its subviews of label and fiddling with their frame sizes. While the instruction view is displayed over the main input view, the touch events are actually still associated with the main input view (and its controls) underneath. Seems like I am forgetting something but i don't know what.
    Your solution will probably work well and it is similar to what I was originally doing in handling the touch events in the main input view view controller. However, technically, it seems kludgy to not be able to handle the touch events in the instruction view view controller where it seems to make more sense to do so.
    Would you or anyone else know why or have any suggestions on things to look out for? The view and controls involved are all supposed to be descendants of UIResponder. Is there a bug or restriction I'm not aware of? Wondering why you went the route you did. Seems like you may have run up against what I am currently facing.

  • Adding a chart to an already existing panel

    I posted this message on the jfreechart forum, but thought I would see if anyone here knows the answer to this:
    I am trying to add a chart to my existing panel. I have 3 tables at the top and want the chart at the bottom. I am just using a demo for now, but once I get this to work, I will be creating my own charts. Here is the way I am calling the LineChartFrame:
    LineChartFrame demo = new LineChartFrame();
    demo.setBounds(new Rectangle(3, 518, 826, 212));
    demo.pack();
    RefineryUtilities.centerFrameOnScreen(demo);
    demo.setVisible(true);
    It brings up another window with the chart in it. Can I add it to my panel like I did with my tables (with scrolling bars so they are listpanes)?:
    jPanel1.add(listPane1, null);
    jPanel1.add(listPane2, null);
    jPanel1.add(listPane3, null);
    I am hoping to do this, but whenever I try this:
    jPanel1.add(demo, null);
    I get an error:
    java.lang.IllegalArgumentException: adding a window to a container
    Can anyone help me out? Thanks.
    Allyson

    I did get a reply from someone on the jfreechart forum, but need to ask more questions. This was his reply:
    Hi Allyson,
    You are trying to add a (subclass of) JFrame to a JPanel...that won't work, of course, and Java tells you so.
    You need to create a ChartPanel to display your chart. This is a subclass of JComponent, which you can happily add to a JPanel (or any other container).
    Regards,
    Dave Gilbert
    Here is the code for the method:
    private void LineChartFrame() {
    double[][] data = new double[][] {
    { 1.0, 4.0, 3.0, 5.0, 5.0, 7.0, 7.0, 8.0 },
    { 5.0, 7.0, 6.0, 8.0, 4.0, 4.0, 2.0, 1.0 },
    { 4.0, 3.0, 2.0, 3.0, 6.0, 3.0, 4.0, 3.0 }
    DefaultCategoryDataset dataset = new DefaultCategoryDataset(data);
    // set the series names...
    String[] seriesNames = new String[] { "First", "Second", "Third" };
    dataset.setSeriesNames(seriesNames);
    // set the category names...
    String[] categories = new String[] { "Type 1", "Type 2", "Type 3", "Type 4", "Type 5", "Type 6", "Type 7", "Type 8" };
    dataset.setCategories(categories);
    // create the chart...
    chart = ChartFactory.createLineChart(
    "Line Chart Demo 1", // chart title
    "Category", // domain axis label
    "Value", // range axis label
    dataset, // data
    true, // include legend
    true, // tooltips
    false); // urls
    chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
    }And I tried this to add it to my panel:
    jPanel1.add(chartPanel, null);But I get this error:
    java.lang.NullPointerException
    ChartPanel is defined globally in this file.
    jPanel1 is my main panel that I want to add the chart to.
    I am putting my last duke dollar on this in the hopes that someone can help. Thanks.
    Allyson

  • Please give me an exemple of an applet using a swing object.

    Please give me an exemple of an applet using a swing object.thank you.

    My problen is that the swing object do not appear in
    my applet. They appear only if i invoque the repaint
    methode.use JApplet, since awt components are heavyweight, and swing components are lightwieght, then your swing components get over painted with aplets background or something.
    anyhow, in your applet you may create JFrame, that would be swing component and if you set it visible, then it will be even visible.
    they say that mixing swing and awt is not good idea, especially when you don't know what you're doing (which might be true in your case)
    so try to migrate your app from AWT based stuff to SWING based stuff, or write your own AWT components that do the job whih you needed swing component for at the first place.
    but if you need to mix awt and swing, then i thing that you should not paint the fole area of applet in applets paint method -- but here i'm not sure, never mixed 'em.
    so you might try to create an applet which paint() method you leave empty and to which you add some JComponent*.
    and see what happens, maybe this JComponent will be visible.
    * -- JComponent is most likely just gray, you might want to add some subclass of it -- JButton, JTextField, JSomethingElse.

Maybe you are looking for