1

私の質問は: 私は CustomCells を持っている TableVC を持っています。これらの customCells にはさまざまなラベルがあり、そのうちの 1 つが Time ラベルです。timeLabel のテキストは、xml の解析によって取得されます。しかし、今のところ、たとえば午後2時45分に静的コンテンツを使用したと仮定しています。このテキストを UILocalNotification の fireDate として指定することは可能ですか?もちろん、その時間に起動する必要があります。「didSelectRowAtIndexPath」にあるセルをクリックすると実行されます。それとも、これはできませんか??

はい、これが繰り返しの質問である場合、気に入らなかった場合、またはスペルミスや関連する何かがある場合は、反対票を投じないでください。私は過去に、人々がそのような安っぽい仕掛けをして、いわゆる評判を不健康で非専門的な方法で利用しているのを見てきました.

関連する回答を歓迎します。

ありがとうございました !!!

編集 私はこのことを試しました

 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];

上記の cellForRowAtIndexPath

-(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 に答える