1

My question is : i have a TableVC wherein i have CustomCells. These customCells have Various Label and one of them is Time label. The text of the timeLabel would be fetched by Parsing an xml. But as of now assuming that i used static content for e.g.: 2:45pm. Is it possible for me to give this text as fireDate of UILocalNotification and off-course it should fire on the said time. It should be done on click of cell that is in "didSelectRowAtIndexPath". Or this cannot be done ??

And yes if this is a repetition question,you did not like it, or if if there is some spelling mistake or anything related Please do not mark it with down votes. I have seen in the past where people play such cheap gimmicks and use their so called reputations in an unhealthy and unprofessional way.

Your related answer's are warmly welcomed.

Thank You !!!

EDIT i tried this thing

 NSString *str = cell.timeLabel.text;
    NSLog(@"str = %@",str);
    formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"MM/dd/yyyy hh:mm a"];
    NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
    [formatter setTimeZone:gmt];
    date = [formatter dateFromString:str];

the above in cellForRowAtIndexPath

and

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{



    UILocalNotification *localNotif = [[UILocalNotification alloc] init];

    localNotif.fireDate = [NSDate dateWithTimeInterval:5 sinceDate:date];

    localNotif.timeZone = [NSTimeZone defaultTimeZone];
    localNotif.alertBody = @"You are notified";
    localNotif.soundName = UILocalNotificationDefaultSoundName;
    [[UIApplication sharedApplication]scheduleLocalNotification:localNotif];

}
4

1 回答 1

1
NSDate *currentDate=[NSDate date];
NSString *dateStr=@"7:10 PM";
UILocalNotification *localNotification =[[UILocalNotification alloc]init];
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"hh:mm a"];
[dateFormatter setTimeZone:gmt];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];

NSString *preFix=[dateFormatter stringFromDate:currentDate];
NSString *datetoFire=[NSString stringWithFormat:@"%@ %@",preFix,dateStr];

[dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm a"];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
[dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm a"];

NSDate *fireDate = [dateFormatter dateFromString:datetoFire];
fireDate=[fireDate dateByAddingTimeInterval:-(60*60*(5.5))];

NSLog(@"date is %@",fireDate);

// Cancel the previously scheduled notification, if any.
if (localNotification == nil) {
    return;
}

localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = @"Good Morning Buddies";
localNotification.alertAction = @"View";
localNotification.fireDate = fireDate;
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber++;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
于 2013-07-12T11:00:35.760 回答