hi! i am new to objective c programming. i am making a quiz application. i have a home screen which options like: view instructions and start quiz. how can i display another view when i click a button. like, i want to display the instruction screen when i click instructions.

can you help me with this one?

Recommended Answers

All 2 Replies

If you have created the view in a nib file then you load the view from the current one. Inside the code for the button press you would have something like:

UIView *quizz = [[UIView alloc] initWithNibName: @"qizzView" bundle: nil];
[currentView addSubView:quizz];

Or possibly the superview would add the subview depending on how you have it set out and want the views to display.

You said you were new to Objective C. Here is a sheet example. I did notice you said view and I am displaying a sheet not a view.
This is a verbose code sample and not a best practice example. I often teach Windows programers how to move to Objective C and bloated codes often helps..

/* Declaration */
- (IBAction)executeAction:sender;


/* Action */
- (IBAction)executeAction:sender
{
    dlgConnection = [[ConnectionMgrDlg alloc]init];

    if(dlgConnection)
    {
        */ params globally declared */
        if(!params)
            params = [[Params alloc] init];

        /* Init and close to attach as a sheet */
        [dlgConnection showWindow:self];
        [[dlgConnection window] setDelegate:dlgConnection];
        [dlgConnection close];
        [dlgConnection setDataValues:params];

        /* Show dialog (sheet) with a response method of didEndExecuteAction */
        [NSApp beginSheet:[dlgConnection window] modalForWindow:window modalDelegate:self didEndSelector:@selector(didEndExecuteSheet:returnCode:contextInfo:) contextInfo:NULL];
    }
}

- (void)didEndExecuteSheet:(NSWindow *)dlg returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
    switch(returnCode)
    {
        case -1: // Cancel
            [dlg orderOut:self];
            break;
        case 1:
            if(params)
            {
                ...
            }
            [dlg orderOut:self];
            break;
    }
    [dlg release];
    dlg = nil;
}

hi! i am new to objective c programming. i am making a quiz application. i have a home screen which options like: view instructions and start quiz. how can i display another view when i click a button. like, i want to display the instruction screen when i click instructions.

can you help me with this one?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.