开发者

iphone passing value to label

开发者 https://www.devze.com 2023-02-13 00:04 出处:网络
I\'m implementing a calendar as part of my app, it shows the selected date in nslog, but I need to send this value to a label,

I'm implementing a calendar as part of my app, it shows the selected date in nslog, but I need to send this value to a label, it show the value as 2011-02-08 in nslog

I created a label in ib,(and connect to it) in *ViewController.h

    IBOutlet UILabel *dateis;

in *ViewController.m

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

[aTile flash];

dateis = [aTile date];

}

but I get the warning>

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

EDIT, if I use

    dateis.text = [aTile date];

I get the warning

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

KLDate is the way the date was defined in the calendar,

开发者_开发技巧
  • so how can I pass this value to the label (working on nslog, view code call in *.m)

Thanks a lot!!


You can't just assign a "Date" to a "Label"...

You are obviously using Appcelerator framework. (KLDate type)

So what you are looking for is :

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

stringWithFormat: will in fact invoke descriptionmethod of KLDate, so you can also use the equivalent :

 dateis.text = aTile.date.description;

To find this look at KLDate.h and check wich method returns a NSString * that you can assign to the good property of UILabel (look its documentation) which is text

You should check description method implementation if you need to write your own code to format the date...


try:

dateis.text = [aTile date];


Well, NSLog can take a lot of different class types as input and it figures out what it can display. What is a KLTile? How are you assigning the date to the KLTile, i.e. from what data structure to what data structure. Somewhere there's gotta be a NSString or a formatted NSDate. Maybe you can see the internal structure of a KLTile in the debugger.


ok, so I dont know if is the proper thing to do, but its working!! (please enlighten me to know if is fine!)

I just figured that if label wanted a string, then I will give it a string, haha, so,

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

[aTile flash];
NSString *str =[NSString stringWithFormat:@"%@", [aTile date]];
dateis.text = str;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号