2

我正在实现一个日历作为我的应用程序的一部分,它在 nslog 中显示选定的日期,但我需要将此值发送到标签,它在 nslog 中将值显示为 2011-02-08

我在 ib 中创建了一个标签,(并连接到它)在 *ViewController.h

    IBOutlet UILabel *dateis;

在 *ViewController.m 中

 - (void)calendarView:(KLCalendarView *)calendarView tappedTile:(KLTile *)aTile{
NSLog(@"Date Selected is %@",[aTile date]);

[aTile flash];

dateis = [aTile date];

}

但我收到警告>

Incompatible Objective-C types assigning 'struct KLDate *', expected 'struct UILabel *'

编辑,如果我使用

    dateis.text = [aTile date];

我收到警告

 incompatible Objective-C types 'struct KLDate *', expected 'struct NSString *' when passing argument 1 of 'setText:' from distinct Objective-C type

KLDate 是在日历中定义日期的方式,

  • 那么如何将此值传递给标签(在 nslog 上工作,在 *.m 中查看代码调用)

非常感谢!!

4

4 回答 4

2

您不能只将“日期”分配给“标签”......

您显然正在使用 Appcelerator 框架。(KLDate类型)

所以你要找的是:

 dateis.text = [NSString stringWithFormat:@"%@", aTile.date];

stringWithFormat:实际上会调用description的方法KLDate,因此您也可以使用等效的方法:

 dateis.text = aTile.date.description;

要找到这个看看 KLDate.h 并检查 wich 方法返回一个NSString *你可以分配给 UILabel 的好属性(查看它的文档),它是text

description如果您需要编写自己的代码来格式化日期,您应该检查方法实现......

于 2011-02-23T00:26:38.333 回答
1

尝试:

dateis.text = [aTile date];
于 2011-02-22T23:48:55.213 回答
1

嗯,NSLog 可以接受很多不同的类类型作为输入,它会计算出它可以显示什么。什么是 KLTile?您如何将日期分配给 KLTile,即从什么数据结构到什么数据结构。某处必须有一个 NSString 或一个格式化的 NSDate。也许你可以在调试器中看到一个 KLTile 的内部结构。

于 2011-02-22T23:50:29.223 回答
1

好的,所以我不知道这样做是否正确,但它的工作原理!(请告知我是否可以!)

我只是想如果label想要一个字符串,那我就给它一个字符串,哈哈,所以,

     - (void)calendarView:(KLCalendarView *)calendarView tappedTile:(KLTile *)aTile{
NSLog(@"Date Selected is %@",[aTile date]);

[aTile flash];
NSString *str =[NSString stringWithFormat:@"%@", [aTile date]];
dateis.text = str;
}
于 2011-02-23T00:19:49.347 回答