initwithint警告,没有找到方法?
我有一个警告,但不知道如何让它消失。
在我的 .h 中我有这个...
-(void)restartTimer;
然后在我的 .m 中我有...
-(void)restartTimer{
TimerViewController *TimerView = [[TimerViewController alloc]
initWithInt:hStart
number:mStart];
我收到此错误:
警告:没有“-initWithInt:number”。方法找到了。
我确信这非常简单,代码仍然有效。如果有人能提出解决问题的任何方法,那就太好了。谢谢
I have a warning and just can't work out how to make it go away.
In my .h I have this...
-(void)restartTimer;
Then the in my .m I have...
-(void)restartTimer{
TimerViewController *TimerView = [[TimerViewController alloc]
initWithInt:hStart
number:mStart];
I get this error:
Warning: no '-initWithInt:number.' method found.
I am sure it is very straightforward, the code still works. If anyone can suggest any ways to solve it that would be great. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
(1)
TimerView
应该是timerView
,按照 Objective-C 命名约定(2) 你的 TimerViewController.h 应该有一个类似这样的声明:(
假设你想要 hStart 和mStart 为整数)。
(3) 您必须直接或间接地在上述代码出现的实现文件中导入 TimerViewController.h(因为它是由其他东西导入的,可能是项目的 PCH 文件)。
(4) 该方法的更好名称可能是:
或类似的名称——也就是说,该方法应该描述它所采用的参数的性质。
(1)
TimerView
should betimerView
, as per Objective-C naming conventions(2) Your TimerViewController.h should have a declaration something like:
(assuming that you want hStart and mStart to be integers).
(3) You must import TimerViewController.h in the implementation file that the above code appears in, either directly or indirectly (because it is imported by something else, potentially the project's PCH file).
(4) A better name for the method might be:
Or something similar -- that is, the method should describe the nature of the arguments that it takes.
这意味着编译器在编译时找不到这样的方法。只需将
TimerViewController
的标头包含在.m
文件中即可。This means the compiler can't find such a method at compile time. Just include the header of
TimerViewController
in your.m
file.导入头文件my.h就可以解决这个问题
Import the header file my .h will resolve this problem
该代码仍然有效,因为 Objective-C 允许向
nil
对象发送消息,因此*TimerView
为nil
。The code still works because Objective-C allows sending messages to
nil
objects thus*TimerView
isnil
.