iPhone 中的代表

发布于 2024-12-27 15:08:24 字数 468 浏览 0 评论 0原文

我正在使用从 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,
enter image description here

enter image description here
Then i synthesize my protocol
enter image description here

enter image description here

but I got the below error. Why, where I am wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

最初的梦 2025-01-03 15:08:24

好吧,我从 github 下载了 Kal。阅读它提供的示例后,我很好奇您如何将 Kal 嵌入到您的项目中。

作为Kal内部的示例项目,它将Kal嵌入到项目中,如下图所示。它会导入 NativeCalAppDelegate.m 中名为 Kal.h 的标头。因此,您的项目中 Kal 的标头搜索路径设置可能有问题。如果将 Kal 编译成静态库,如何引用 Kal 的头文件?

Kal example project

编辑

我修改了NativeCal的示例并上传整个 Kal 项目此链接,这是可下载的。

就可以编译成功了。以下是我修改后的一些图片。

关于标头内的 KalViewControllerDelegate
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 the Kal into project as the following image. And it imports the header named Kal.h in NativeCalAppDelegate.m. So, there may be something wrong about the setting of header search path for Kal inside your project. If you compiler the Kal into a static library, how you reference the header files of Kal ?

Kal sample project

Edit

I modify the example of NativeCal and upload the whole Kal 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
The declaration of KalViewControllerDelegate

Declare the implementation of KalViewControllerDelegate
enter image description here
enter image description here

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.
enter image description here
enter image description here

ˇ宁静的妩媚 2025-01-03 15:08:24

您需要 #import 已声明 KalViewControllerDelegate 协议的 .h 头文件。

You need to #import the .h header file where you have declared your KalViewControllerDelegate protocol.

痴骨ら 2025-01-03 15:08:24

不确定这是否有帮助,但是当我使用 Kal 时,我就是这样做的:

#import <UIKit/UIKit.h>
#import "SomeOfMyClasses.h"
#import "Kal.h"

@interface SomeRandomViewController : UIViewController<UITableViewDataSource, UITableViewDelegate, KalViewDelegate>

如你所见,我使用了 KalViewDelegate 而不是 KalViewControllerDelegate。另外不要忘记导入“Kal.h”。

更新

中执行了以下操作:

self.kvc = [[KalViewController alloc]init];
self.kvc.delegate = self;
self.kvc.view.frame = CGRectMake(0, 0, 320, 340);

我在 viewDidLoad 方法和头文件

@property (nonatomic, retain) KalViewController *kvc;

Not sure if that will help, but when I used Kal I did it that way:

#import <UIKit/UIKit.h>
#import "SomeOfMyClasses.h"
#import "Kal.h"

@interface SomeRandomViewController : UIViewController<UITableViewDataSource, UITableViewDelegate, KalViewDelegate>

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:

self.kvc = [[KalViewController alloc]init];
self.kvc.delegate = self;
self.kvc.view.frame = CGRectMake(0, 0, 320, 340);

and header file:

@property (nonatomic, retain) KalViewController *kvc;
岁月如刀 2025-01-03 15:08:24

哈哈,我很好奇为什么你做不到,所以我决定自己下载该课程。有趣的是我没有遇到任何问题。

这就是我所做的:(

我假设您想为 KalViewController.h 类创建一个新协议)
所以你

在下面添加“@class KalLogic, KalDate;”

@protocol KalViewControllerDelegate <NSObject>

-(void)dateDidSelected:(NSDate *)selectedDate;

@end

然后在声明属性的同一头文件中添加:

@property (nonatomic, assign) id<KalViewControllerDelegate> delegate2;

请注意,此标头已经实现了委托

@property (nonatomic, assign) id<UITableViewDelegate> delegate;

,因此您必须将其命名为委托以外的其他名称。

然后在该类的实现文件中合成该名称:

@synthesize dataSource, delegate, initialDate, selectedDate, delegate2;

然后您可以在任何需要的地方实现该委托。我不知道这个 kal 项目是做什么的,所以我选择了一个随机文件(在本例中为 SBJSON.h)

并添加了(在标题上)

@interface SBJSON : SBJsonBase <SBJsonParser, SBJsonWriter, KalViewControllerDelegate> {

和(在实现上)

- (void)dateDidSelected:(NSDate *)selectedDate
{

}

希望这有帮助,祝你好运

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;"

@protocol KalViewControllerDelegate <NSObject>

-(void)dateDidSelected:(NSDate *)selectedDate;

@end

then in the SAME header file where the properties are declared you add:

@property (nonatomic, assign) id<KalViewControllerDelegate> delegate2;

Please note that this header already has a delegate implemented

@property (nonatomic, assign) id<UITableViewDelegate> delegate;

so you have to name it something else other than delegate.

then on the implementation file of that class you syntethize that name:

@synthesize dataSource, delegate, initialDate, selectedDate, delegate2;

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)

@interface SBJSON : SBJsonBase <SBJsonParser, SBJsonWriter, KalViewControllerDelegate> {

and (on the implementation)

- (void)dateDidSelected:(NSDate *)selectedDate
{

}

Hope this helps, Good luck

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文