- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我试图将我的 UIView 类的实现转换为我的 View Controller 。但是,当尝试为我的类调用方法时,它会抛出“发送到实例的无法识别的选择器”。
这是我在头文件中所做的:
#import <UIKit/UIKit.h>
@interface GameViewController : UIViewController{
NSTimer *gameLoop;
}
- (IBAction)quitGame:(id)sender;
- (IBAction)rotateLeft:(id)sender;
- (IBAction)rotateRight:(id)sender;
- (IBAction)thrust:(id)sender;
@end
typedef enum { NOTREADY, READY, RUNNING, WON, LOST, PAUSED } GameState;
typedef enum { EASY, MEDIUM, HARD } GameDifficulty;
typedef enum { THRUSTERS_ON, THRUSTERS_OFF } ThrusterState;
// Declaration of other constants used to manage the physics
static const int FUEL_INITIAL = 200;
static const int FUEL_MAX = 200;
static const int FUEL_BURN = 10;
static const int MAX_INIT = 30;
static const int MAX_SPEED = 120;
static const int ACCELERATION_DOWN = 35;
static const int ACCELERATION_UP = 80;
static const double GRAVITY = 9.8;
@interface GameView : UIView {
@private UIImage *plander_thrust;
@private UIImage *plander_nothrust;
@private UIImage *plander_crashed;
// Other game member variables
@private GameState gstate;
@private GameDifficulty level;
@private ThrusterState thrusters;
@private int fuel;
@private int speed_x;
@private int speed_y;
@private double rotation;
// Define our lander’s X and Y on-screen coordinates
@private int loc_x;
@private int loc_y;
}
@property (nonatomic, retain) UIImage *lander_nothrust;
// Declare our class methods
- (void) newGame;
- (void) updateLander;
- (void) rotateLeft:(id)sender;
- (void) rotateRight:(id)sender;
- (void) thrustEngine:(id)sender;
@end
现在,这是我对我的 .m 文件所做的:
#import "GameView.h"
@implementation GameViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (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.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
//'timerLoop' function
gameLoop = [NSTimer scheduledTimerWithTimeInterval: 0.025 target:self selector:@selector(timerLoop:) userInfo:nil repeats:YES];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void) timerLoop:(NSTimer *)timerObj {
//so this is where I am getting the error
[(GameView *)self.view updateLander];
[self.view setNeedsDisplay];
}
- (IBAction)quitGame:(id)sender {
[self dismissModalViewControllerAnimated:true];
}
- (IBAction)rotateLeft:(id)sender {
[(GameView *)self.view rotateLeft:sender];
}
- (IBAction)rotateRight:(id)sender {
[(GameView *)self.view rotateRight:sender];
}
- (IBAction)thrust:(id)sender {
[(GameView *)self.view thrustEngine:sender];
}
@end
@implementation GameView
@synthesize lander_nothrust;
-(id)initWithCoder:(NSCoder *)aDecoder{
if(self == [super initWithCoder:aDecoder]){
//initialize sprites
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"lander" ofType:@"tiff"];
self.lander_nothrust = [UIImage new];
self.lander_nothrust = [UIImage imageWithContentsOfFile:imagePath];
[self newGame];
}
return self;
}
-(void) newGame{
gstate = READY;
level = EASY;
thrusters = THRUSTERS_OFF;
fuel = FUEL_INITIAL;
loc_x = self.frame.size.width / 2;
loc_y = self.frame.size.height / 2;
// Set the game as RUNNING
gstate = RUNNING;
}
-(void)updateLander{
}
// rotateLeft - rotate the lander left
- (void)rotateLeft:(id)sender
{
// Do Something
}
// rotateRight - rotate the lander right
- (void)rotateRight:(id)sender
{
// Do Something
}
// thrustEngine - fire the thruster on the engine
- (void)thrustEngine:(id)sender
{
// Do Something
}
-(void)drawRect:(CGRect)rect{
if(gstate != RUNNING){
return;
}
[self.lander_nothrust drawAtPoint:CGPointMake(loc_x, loc_y)];
self.backgroundColor = [UIColor redColor];
}
@end
如上所示,这行代码出现错误:
[(GameView *)self.view updateLander];
我环顾四周,一直听说这是因为我正在调用一个对我的对象不存在的方法,但我不确定为什么它看不到我的对象实现。我什至将身份检查器中 UIView 的自定义类设置为“GameView”作为我的类。
最佳答案
问题出在你的 Nib 上。您尚未将 View 的自定义类设置为 GameView
,或者您尚未将 File's Owner 的 view
导出连接到该 View 。
关于iphone - 为 UIView 获取 "unrecognized selector sent to instance",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9155343/
我想知道这两者之间有什么不同 .myClass/DomElement .myotherclassinsidethatelement 和 .myClass/DomElement > .myothercl
使用 jQuery on() 版本 1.7。我通常这样绑定(bind)我的事件: $(".foo").on("click", function() { console.log("foo cli
我想找到与选择器匹配的所有元素,但如果它已经包含在匹配元素中则不查找。 $('#container').find('.child').not('.child .child'); 请注意,.child
我有一个看起来像这样的无序列表,但更广泛: Parent Category 2 Parent Category 2 Parent Category 3
这个问题在这里已经有了答案: CSS negation pseudo-class :not() for parent/ancestor elements (2 个答案) 关闭 4 年前。
我希望使用 CSS :not() 来定位 before 选择器。这可能吗? 示例: https://jsfiddle.net/uuq62b8d/ a.button:before { content
这有什么区别: $.each($('#myTable input[name="deleteItem[]"]:checked').do_something()); 还有这个: $('#myTable i
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我正在使用 UL LI 列表和 jQuery 创建一棵树。我使用了 jQuery 选择器 jQuery(li:has(ul)) 查找所有具有子节点的列表节点,然后向其添加单击事件。 jQuery(li
我真的不知道如何命名这两种方法,所以请原谅我这样调用它们。 字符串选择器 $("#myList li").eq(3); 函数选择器 $("#myList li:eq(3)"); 据我所知,他们都做同样
我有以下代码: .. 我正在使用以下 CSS 来排除具有“main-l tbl”类的表: table:not(.main-l .views-table) { .. } 我注
这个问题已经有答案了: 已关闭12 年前。 Possible Duplicate: What is the difference between $ and jQuery 我注意到使用“jQuery(
我有许多 css 选择器和许多选择器异常,所以我使用 :not 将它们排除在外... 示例(只是一些我不需要的选择器): [class*="-dashboard-"]:not([class$="-bi
CADisplayLink 有这个方法是有道理的,但我很好奇为什么 UIScreen 也会有它。 最佳答案 文档说屏幕提供的显示链接与该屏幕相关联。但是,查看官方文档,与任何屏幕都没有明显的关系;显示
我在这里阅读了关于 toArray() 的文档,并在控制台中对其进行了测试。我找不到在选择器上调用 toArray() 和调用选择器本身之间的区别。 两种方式都得到了完全相同的结果,这是一个与选择器匹
我有一个问题,为什么这两个代码片段不同。 $('#ctl00_DDMenu1_HyperLink1') //jQuery(a#ctl00_DDMenu1_HyperLink1 Default.asp
我想通过以下方式模拟我可以在 jQuery 中实现的目标$('.someClass:not(.hidden)') 我试过下面的代码。 $crawler->filter('someClass:not(.
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我想通过以下方式模拟我可以在 jQuery 中实现的目标$('.someClass:not(.hidden)') 我试过下面的代码。 $crawler->filter('someClass:not(.
我想根据 Iterator::next 中当前枚举变体的某些属性更改枚举变体。我有两次尝试,都没有编译: enum Test { A(Vec), B, } impl Iterator
我是一名优秀的程序员,十分优秀!