0

我的问题是我有一个包含标签的自定义单元格。标签的值将通过 webServices 获取,该值将在 TIME 中。最初,如果我们使用静态数据,例如:晚上 10:54,然后单击该单元格,它应该提醒我在标签上设置的值。当然应该在上述时间通知我。

-(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];
    localNotification.alertBody=@"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;
}

我试过这样做,但这不起作用。

谢谢你。

4

1 回答 1

0

获取一个动态数组,该数组将包含从 web 服务填充的值,并将填充的时间动态放入 cell.In cellForRow 方法中。

我采用了静态数组,如下所示

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

您必须动态地将值放入此数组中,因为您将从 web 服务中获取填充数据。并重新加载表。

- (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];
于 2013-07-15T05:26:21.010 回答