使用xCode 6.1.1,Objective C
我是Objective C的初学者,现在正尝试将其他一些方法扩展到iOS4的现有APP项目。
在我实现新方法并通过我的ViewController_2调用它之后,它工作很奇怪:调用该方法但它没有收到参数。但是如果我在现有的ViewController中调用相同的方法,它可以正常工作。
有人可以告诉我班上的问题是什么吗?
这是我的代码:
//我的自定义班级
AnimationObjectContainer.h
#import <Foundation/Foundation.h>
@interface AnimationObjectContainer : NSObject
...
- (void)flashImagesForSecs:(CGFloat)seconds;
...
@end
AnimationObjectContainer.m
#import "AnimationObjectContainer.h"
@implementation AnimationObjectContainer
- (void)flashImagesForSecs:(CGFloat)seconds
{
NSLog(@"flashImagesForSecs: is called. seconds = %f", seconds);
}
@end
//现有项目ViewController
ViewController.m
AnimationObjectContainer *container = [[AnimationObjectContainer alloc] init];
[container flashImagesForSecs:30]; // Succeed.
//我自定义的ViewController,继承了ViewController.h ViewController_2.h
#import <UIKit/UIKit.h>
#import "ViewController.h"
@interface ViewController_2 : ViewController <UIGestureRecognizerDelegate>
...
@end
ViewController_2.m
#import "ViewController_2.h"
#import "AnimationObjectContainer.h"
@implementation ViewController_2
...
AnimationObjectContainer *container = [[AnimationObjectContainer alloc] init];
// Warning displayed here: Instance method '-flashImagesForSecs:' not found(return type defaults to 'id')
[container flashImagesForSecs:30]; // Succeed but output: 2015-02-09 10:28:28.959 Fomm Panel[2728:1765749] flashImagesForSecs: is called. seconds = 0.000000
...
@end
答案 0 :(得分:0)
自己回答。
我检查并修改了这些东西,然后才有效。但警告信息仍然存在。我不知道如何摆脱它...
self =(AnimationObjectContainer *)0x16657c30
秒=(CGFloat)0.00000000000000000000000000000420389539
self =(AnimationObjectContainer *)0x15e69940
seconds =(int)30
我不确定这里发生了什么,但确实有效 但是,警告信息“找不到实例方法”仍然存在。