开发者

Changed nib File to a OPGL ES View, Buttons don't work

Hy,

There is no problmen with changing the nib but when I'm in the nib-File with the OPGL ES view my buttons that are integrated in this view won't work. When I press one the application crashes.

This is the Code how I change the View to the Second Nib:

- (IBAction)drawEAGLView:(id)sender {

NSArray* nibViews =  [[NSBundle mainBundle] loadNibNamed:@"settingsViewController" owner:self options:nil];
EAGLView* glView = [ nibViews objectAtIndex: 1];
self.view = glView;
[glView startAnimation];}

The Animation is working .

This is the Code of the ViewController where the Button is declared:

SettingsViewController.h:

#import <UIKit/UIKit.h>


@interface SettingsViewController : NSObject {

    IBOutlet UIButton *wowButton;
}
@property(nonatomic,retain) IBOutlet UIButton *wowButton;

- (IBAction)wowButtonPressed:(id)sender;

int testvarAnimation;
int animNext;


@end

SettingsViewController.m:

#import "SettingsViewController.h"
@implementation SettingsViewController
@implementation SettingsViewController
@synthesize wowButton;


- (IBAction)wowButtonPressed:(id)sender{
    NSLog(@"TOUCHED");
    //testvarAnimation = 1;
    animNext =1;

}

- (void)dealloc {
    [wowButton release];
    [super dealloc];
}


@end

Here I show you how I connected the Function开发者_如何转开发s and the Outlets: http://s3.imgimg.de/uploads/screenshotConna91ea645png.png

Please tell me If you need more informations.

Thanks


Hy I solved my problem, I rewrote my drawEAGLView Methode:

- (IBAction)drawEAGLView:(id)sender {

    SettingsViewController *sViewController = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
        [[self.view superview] addSubview:sViewController.view];

    }

I also corrected my SettingsViewController.h:

#import <UIKit/UIKit.h>


@class EAGLView;

@interface SettingsViewController : UIViewController {

    IBOutlet UIButton *wowButton;

    EAGLView *glview;
}
@property(nonatomic,retain) IBOutlet UIButton *wowButton;
@property (nonatomic, retain) IBOutlet EAGLView *glView;

- (IBAction)wowButtonPressed:(id)sender;

int testvarAnimation;
int animNext;


@end

And last but not least I changed my SettingsViewController.m:

#import "SettingsViewController.h"
#import "EAGLView.h"



@implementation SettingsViewController

@synthesize wowButton, glView;


- (IBAction)wowButtonPressed:(id)sender{
    NSLog(@"TOUCHED");
    //testvarAnimation = 1;
    animNext =1;
}

- (void)viewDidLoad {
    glView.animationInterval = 1.0 / 60.0;
    [glView startAnimation];

    [super viewDidLoad];
}
- (void)dealloc {
    [wowButton release];
    [super dealloc];
}


@end

I also changed my Nib file. I removed the ViewController and set the type of the File's Owner to my viewController named "SettingsViewController". I connected the File's Owner Outlet view with the EAGLView and the button with the SettingsViewControllers wowButtonPressed Method

I hope I could help also someone else,

Thanks


Here is the right solution for this problem:

First you have to create a parnet object of your view you want to be shown as first. You need to do this in the header file of the second view.

//
//  SettingsViewController.h
//  NeheTutorial2
//
//  Created by Global Sound on 05.04.11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@class EAGLView;
@class mobilesynthViewController;

@interface SettingsViewController : UIViewController {

    IBOutlet UIButton *wowButton;
    IBOutlet UIButton *optiButton;

    EAGLView *glView;
    //mobilesynthViewController *mViewController;
    mobilesynthViewController *parent;
}
@property(nonatomic,retain) IBOutlet UIButton *wowButton;
@property(nonatomic,retain) IBOutlet UIButton *optiButton;
@property (nonatomic, retain) IBOutlet EAGLView *glView;
//@property(nonatomic,retain) IBOutlet mobilesynthViewController *mViewController;

@property (nonatomic, retain) mobilesynthViewController *parent;

- (IBAction)wowButtonPressed:(id)sender;

- (IBAction)optiButtonPressed:(id)sender;

int testvarAnimation;
int animNext;
int musicOn;
int isAnimating;
float zaehler;


@end

Now in the implemetaion File you need to add the parent object to your function:

#import "SettingsViewController.h"
#import "EAGLView.h"
//#import "mobilesynthViewController.h"


@implementation SettingsViewController

@synthesize wowButton, optiButton, glView;//,mViewController;
@synthesize parent;

- (IBAction)wowButtonPressed:(id)sender{
    NSLog(@"TOUCHED");
    [parent startThread];
    [parent showbButtonStop];
    testvarAnimation = 0;
    animNext =1;
    //musicOn =1;
}

- (IBAction)optiButtonPressed:(id)sender{

    NSLog(@"OPTIONS ON");
    [self dismissModalViewControllerAnimated:YES];
    [parent showbButton];



    //mobilesynthViewController *aRootViewController = [[mobilesynthViewController alloc] initWithNibName:@"mobilesynthViewContoller" bundle:nil];
    //[self setRootViewController:aRootViewController];
    //[aRootViewController release]; 


    //mobilesynthViewController *mViewController = [[mobilesynthViewController alloc] initWithNibName:@"mobilesynthViewController" bundle:nil];
    //[[self.view superview] addSubview:mViewController.view];
    //self.view = mViewController;

    //CGRect rect = [[UIScreen mainScreen] applicationFrame];
    //mViewController = [[mobilesynthViewController alloc] initWithFrame:CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)];
    //self.view = mViewController;

}

- (void)viewDidLoad {
    glView.animationInterval = 1.0 / 60.0;
    [glView startAnimation];

    [super viewDidLoad];
}
/*

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
*/
- (void)dealloc {
    [wowButton release];
    [optiButton release];
    [super dealloc];
}


@end

In my case I'm calling a other function in the main View of my program. When the button in the second view is pressed the function in the first view is called through the the parent object

[parent startThread];

Again the startThread methode was declerated in another view.

I hope I could help you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜