iPhone 中的代表
我正在使用从 github 下载的自定义 Kal 日历视图库。我非常清楚并成功执行如何创建委托协议并实现它们。 但现在在我的应用程序中我必须这样做,当用户单击日期时,该日期直接反映到我的 UIViewController 类。对于该场景,我使用了 @protocol 委托方法,但我遇到了奇怪的问题。请看下面的截图并指出我哪里错了,
然后我综合我的协议
但我收到以下错误。为什么,我哪里错了?
I am using custom Kal calender view library downloaded from github. I know very well and execute successfully how to create delegate protocol and implement them.
But now in my application I have to do, when user click on date that date directly reflect to my UIViewController class. For that scenario I used @protocol
delegate method but I got strange problem in it. Please see the following screenshot and suggest me where I am wrong,
Then i synthesize my protocol
but I got the below error. Why, where I am wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好吧,我从 github 下载了 Kal。阅读它提供的示例后,我很好奇您如何将
Kal
嵌入到您的项目中。作为
Kal
内部的示例项目,它将Kal
嵌入到项目中,如下图所示。它会导入NativeCalAppDelegate.m
中名为Kal.h
的标头。因此,您的项目中Kal
的标头搜索路径设置可能有问题。如果将Kal
编译成静态库,如何引用Kal
的头文件?编辑
我修改了
NativeCal
的示例并上传整个Kal 项目
到此链接,这是可下载的。就可以编译成功了。以下是我修改后的一些图片。
关于标头内的 KalViewControllerDelegate
声明 KalViewControllerDelegate 的实现
编辑最终
我终于找到了
NativeCal 可以正确导入标头。导入xcode项目后进行的设置如下图所示。
Well, I downloaded the Kal from github. After reading the sample it provides, I am curious how you embedded the
Kal
into your project.As the sample project inside
Kal
, it embedded theKal
into project as the following image. And it imports the header namedKal.h
inNativeCalAppDelegate.m
. So, there may be something wrong about the setting of header search path forKal
inside your project. If you compiler theKal
into a static library, how you reference the header files ofKal
?Edit
I modify the example of
NativeCal
and upload the wholeKal project
to this link, which is downloadable.It is successful to compile. The followings are some images about what I modified.
About KalViewControllerDelegate inside the header
Declare the implementation of KalViewControllerDelegate
Edit Final
I finally found out why the
NativeCal
can import header correctly. It did the settings after import the xcode project as following images.您需要 #import 已声明
KalViewControllerDelegate
协议的 .h 头文件。You need to #import the .h header file where you have declared your
KalViewControllerDelegate
protocol.不确定这是否有帮助,但是当我使用 Kal 时,我就是这样做的:
如你所见,我使用了 KalViewDelegate 而不是 KalViewControllerDelegate。另外不要忘记导入“Kal.h”。
更新
中执行了以下操作:
我在 viewDidLoad 方法和头文件
Not sure if that will help, but when I used Kal I did it that way:
as you can see, I used KalViewDelegate and not KalViewControllerDelegate. Also don't forget to import "Kal.h".
Update
I did the following in my viewDidLoad method:
and header file:
哈哈,我很好奇为什么你做不到,所以我决定自己下载该课程。有趣的是我没有遇到任何问题。
这就是我所做的:(
我假设您想为 KalViewController.h 类创建一个新协议)
所以你
在下面添加“@class KalLogic, KalDate;”
然后在声明属性的同一头文件中添加:
请注意,此标头已经实现了委托
,因此您必须将其命名为委托以外的其他名称。
然后在该类的实现文件中合成该名称:
然后您可以在任何需要的地方实现该委托。我不知道这个 kal 项目是做什么的,所以我选择了一个随机文件(在本例中为 SBJSON.h)
并添加了(在标题上)
和(在实现上)
希望这有帮助,祝你好运
Haha i was very curios about why you couldnt make it, so i decided to download the class myself. Funny thing is i DIDNT get any problems.
Here is what i did:
(i assume you want to create a new protocol for the class KalViewController.h)
so you add
Bellow the "@class KalLogic, KalDate;"
then in the SAME header file where the properties are declared you add:
Please note that this header already has a delegate implemented
so you have to name it something else other than delegate.
then on the implementation file of that class you syntethize that name:
and then you can implmeneted that delegate whever you want. I have no idea what this kal project does so i picked a random file (in this case SBJSON.h)
and added the (on the header)
and (on the implementation)
Hope this helps, Good luck