2013-07-12 2 views
1

Мой вопрос: У меня есть TableVC, в котором у меня есть CustomCells. Эти customCells имеют различную метку, а одна из них - метка времени. Текст метки времени будет получен с помощью анализа xml. Но теперь, полагая, что я использовал статический контент, например: 2:45 вечера. Возможно ли, чтобы я дал этот текст как fireDate UILocalNotification и вне курса, он должен срабатывать в указанное время. Это нужно сделать по щелчку ячейки, которая находится в «didSelectRowAtIndexPath». Или это невозможно сделать ???Вызов UILocalNotification на основе текста/значения метки

И да, если это вопрос повторения, вам это не понравилось, или если есть какая-либо орфографическая ошибка или что-то связанное Пожалуйста, не отмечайте это с пустым голосованием. Я видел в прошлом, когда люди играют такие дешевые трюки и используют свою так называемую репутацию нездоровым и непрофессиональным способом.

Ваш родственный ответ приветствуется.

Thank you !!!

EDIT я попробовал эту вещь

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

} 
+0

может быть это поможет U http://stackoverflow.com/a/10041471/1305001 – Warewolf

+0

@Her çules: Спасибо за ответ. Но я не хочу, чтобы он повторялся. Когда пользователь нажимает на ячейку, он должен вызывать всплывающее окно, которое вы обязательно хотите добавить, если пользователь нажимает «да», тогда он должен установить на основе fireDate на значение, присвоенное метке в ячейке. –

+0

только один раз хотите ли вы стрелять по тревоге? – Warewolf

ответ

1
NSDate *currentDate=[NSDate date]; 
NSString *[email protected]"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]; 
+0

Геркулес: +1. Спасибо –