UIDatePicker and UITextView
I want to show a text in UITextView
depend on the date, some thing like "in This Day App", I have this code in action
-(void)changingText:(id)sender {
NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.dateStyle = NSDateFormatterMediumStyle;
label.text = [NSString stringWithFormat:@"%@", [df stringFromDate:datePicker.date]];
NSDictionary *pageData = [[DataSource sharedDataSource] dataForPage:pageIndex];
NSString *dateText = [pageData objectForKey:@"pageName"];
NSString *dateInfo = [df stringFromDate:datePicker.date];
if ([dateText isEqualToString: dateInfo]) {
myText.text = [pageData objectForKey:@"pageText"];
}
[df release];
}
My qustion is how to update UITextView
With the data from NSDictionery ForKey@"pageText"
, because it shows just the first object.
here is the Object that i want to triger when the date been se开发者_开发百科lected.
- (id)init {
self = [super init];
if (self != nil)
{
dataPages = [[NSArray alloc] initWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:
@"Oct 3, 2009", @"pageName",
@"First Object", @"pageText",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
@"Oct 10, 2009", @"pageName",
@"second Object", @"pageText",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
@"Oct 27, 2009", @"pageName",
@"Third Object", @"pageText",
nil],
nil];
}
return self;
}
I'm not sure if I understand your question, but I think you need to make the object from your dictionary into an NSString like this:
-(void)changingText:(id)sender{
NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.dateStyle = NSDateFormatterMediumStyle;
NSDictionary *pageData = [[DataSource sharedDataSource] dataForPage:pageIndex];
NSString *dateText = (NSString *)[pageData objectForKey:@"pageName"];
NSString *dateInfo = [df stringFromDate:datePicker.date];
label.text = [NSString stringWithFormat:@"%@", [df stringFromDate:dateInfo]];
if ([dateText isEqualToString: dateInfo]) {
myText.text = dateText;
}
[df release];
}
精彩评论