質問

My problem is I have a Custom Cell which contains a label. The value of label would be fetched via webServices which would be in TIME .Initially if we go by static data i.e. for e.g.: 10:54 PM, then on click of that cell it should set me a reminder of that value set on label.And off course should notify me on the said time.

-(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;
}

I tried doing this, but this isn't working.

Thank You.

役に立ちましたか?

解決

Take a dynamic array that will contain values populated from webservice and put populated time to cell dynamically in your cell.In cellForRow method.

I have taken static array as given below

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

you have to put values in this array dynamically as u will get populated data from webservice. and reload table.

- (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;
}

And in did select method assign fire date from array not from cell text label as

NSString *dateStr=[time objectAtIndex:indexPath.row];
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top