2013-07-15 1 views
0

Моя проблема заключается в том, что у меня есть пользовательская ячейка, которая содержит метку. Значение метки будет выбрано через веб-службы, которые будут находиться в TIME. Первоначально, если мы идем статическими данными, например, например: 10:54 PM, то при нажатии этой ячейки он должен установить мне напоминание об этом значении, установленном на ярлыке Конечно, я должен сообщить об этом в указанное время.Установить FireDate из UILocalNotification на основе (динамического) значения метки

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

    CC *cell=(CC*)[tableView cellForRowAtIndexPath:indexPath]; 

    NSDate *currentDate=[NSDate date]; 

    NSString *dateStr= cell.timeLabel.text; 

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

    NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; 
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
    [dateFormatter setLocale:[NSLocale currentLocale]]; 
    [dateFormatter setDateStyle:NSDateFormatterNoStyle]; 
    [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; 
    [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"]; 

    NSLog(@"date is %@",[dateFormatter dateFromString:datetoFire]); 


    if (localNotification==nil) { 
     return; 
    } 


    localNotification.fireDate=[dateFormatter dateFromString:datetoFire]; 
    localNotification.timeZone=[NSTimeZone defaultTimeZone]; 
    [email protected]"Good Morning dude..!"; 
    localNotification.repeatInterval=0; //The default value is 0, which means don't repeat. 
    localNotification.soundName=UILocalNotificationDefaultSoundName; 
    [[UIApplication sharedApplication]scheduleLocalNotification:localNotification]; 

} 



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    CC *cell = (CC *) [tableView dequeueReusableCellWithIdentifier:@"CC"]; 
    if (cell == nil) { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CC" owner:self options:nil]; 
     cell = (CC *) [nib objectAtIndex:0]; 
    } 


    return cell; 
} 

Я пробовал делать это, но это не работает.

Thank you.

+0

показать мне свой код cellforrow также, как у вкладывает значение в камеру – Warewolf

+0

@ HERCULES: Пожалуйста, проверьте отредактированный вопрос. –

ответ

0

Возьмите динамический массив, который будет содержать значения, занесенные из webservice, и динамически добавит в ячейку заполненное время в ячейке. В методе cellForRow.

Я взял статический массив, как указано ниже

time = [[NSMutableArray alloc] initWithObjects:@"5:35 PM",@"4:56 AM",@"6:00 PM",@"7:32 AM",nil]; 

Вы должны поместить значения в этом массиве динамически и будет получать заселена данные из веб-сервиса. и перезагрузить таблицу.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    CC *cell = (CC *) [tableView dequeueReusableCellWithIdentifier:@"CC"]; 
    if (cell == nil) { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CC" owner:self options:nil]; 
     cell = (CC *) [nib objectAtIndex:0]; 
    } 

    cell.textLabel.text=[time objectAtIndex:indexPath.row]; 

    return cell; 
} 

И сделал выберите метод назначение даты огня из массива не из текста ячейки наклейки

NSString *dateStr=[time objectAtIndex:indexPath.row]; 
+0

Геркулес: Работает отлично! Спасибо –