Search code examples
iphoneuilabelnslog

iphone passing value to 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!!


Solution

  • 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...