【问题标题】:Changed nib File to a OPGL ES View, Buttons don't work将 nib 文件更改为 OPGL ES 视图,按钮不起作用
【发布时间】:2011-04-29 15:11:54
【问题描述】:

喂,

更改笔尖没有问题,但是当我在 OPGL ES 视图的笔尖文件中时,集成在此视图中的按钮将不起作用。当我按下一个时,应用程序崩溃了。

这是我如何将视图更改为第二个笔尖的代码:

- (IBAction)drawEAGLView:(id)sender {

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

动画正在运行。

这是声明 Button 的 ViewController 的代码:

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

在这里,我向您展示了我是如何连接功能和插座的: http://s3.imgimg.de/uploads/screenshotConna91ea645png.png

如果您需要更多信息,请告诉我。

谢谢

【问题讨论】:

  • 您将不得不提供更多信息。我只能建议你研究 XCode 创建的 OpenGL ES 示例项目,并尝试看看它和你的有什么不同。
  • 很抱歉我没有提供足够的信息,但我已经改变了解决这个问题的方法,但我不知道如何编辑我的问题,或者我应该发布一个新问题吗?
  • 好的,我设法编辑了这个问题 =)

标签: iphone cocoa-touch opengl-es rendering


【解决方案1】:

我解决了我的问题,我重写了我的 drawEAGLView 方法:

- (IBAction)drawEAGLView:(id)sender {

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

    }

我还更正了我的 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

最后但同样重要的是,我更改了我的 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

我还更改了我的 Nib 文件。我删除了 ViewController 并将文件所有者的类型设置为名为“SettingsViewController”的 viewController。我将 File's Owner Outlet 视图与 EAGLView 和按钮与 SettingsViewControllers wowButtonPressed 方法连接

我希望我也能帮助别人,

谢谢

【讨论】:

  • 嘿,又是我,我找到了解决此问题的更好方法,因为此解决方案会使设备上的应用程序崩溃。我会在 2011 年 5 月 7 日发布更好的。对此我很抱歉,但我真的很紧张,很快我就要在学校进行期末考试了!
【解决方案2】:

这是解决这个问题的正确方法:

首先,您必须创建一个您希望首先显示的视图的parnet 对象。 您需要在第二个视图的头文件中执行此操作。

//
//  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

现在在实现文件中,您需要将父对象添加到您的函数中:

#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

在我的例子中,我在程序的主视图中调用了另一个函数。当按下第二个视图中的按钮时,通过父对象调用第一个视图中的函数

[parent startThread];

startThread 方法再次在另一个视图中被取消。

希望能帮到你。

【讨论】:

    猜你喜欢
    • 2017-10-24
    • 2016-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多