didSelectRowAtIndexPath没被调用?

时间:2014-05-02 14:35:11

标签: ios objective-c cocoa-touch uitableview didselectrowatindexpath

由于某些奇怪的原因,我的代码中没有调用didSelectRowAtIndexPath。有谁知道为什么?其他一切都有效,可能与我的部分有关。我不明白为什么我的删除类有效但didSelectRowAtIndexPath没有。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return self.subjectArray.count;

}



- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    return [self.subjectArray objectAtIndex:section];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [[self.sectionArrays objectAtIndex:section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableViewer cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *currentSectionArray = [self.sectionArrays objectAtIndex:indexPath.section];

    //populates the table based on which view is selected.

    UITableViewCell *cell = [tableViewer dequeueReusableCellWithIdentifier:@"todayCell"];
    NSString *toDoItem = [currentSectionArray objectAtIndex:indexPath.row];
    cell.textLabel.text = toDoItem;

    cell.textLabel.adjustsFontSizeToFitWidth = YES;
    cell.textLabel.minimumScaleFactor = 0.5;



        cell.accessoryType = UITableViewCellAccessoryCheckmark;

        cell.accessoryType = UITableViewCellAccessoryNone;


    return cell;



}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return YES if you want the specified item to be editable.
    return YES;
}

// Override to support editing the table view.
- (void)tableView:(UITableView *)tableViews commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {


    if (editingStyle == UITableViewCellEditingStyleDelete) {

        NSMutableArray *currentSectionArray = [self.sectionArrays objectAtIndex:indexPath.section];
        NSString *currentStringSubject = [self.subjectArray objectAtIndex:indexPath.section];





        NSMutableDictionary *tempDic = [self.mainDictionary objectForKey:currentStringSubject];


        NSArray *temp = [tempDic allKeysForObject:[currentSectionArray objectAtIndex:indexPath.row]];
        NSString *key = [temp lastObject];




        int keyInt = [key integerValue];
        int maxKey = [[[tempDic allKeys]lastObject]integerValue];
        NSLog(@"KEYINT%d",keyInt);

        [tempDic removeObjectForKey:key];


        if (keyInt != maxKey) {
            for (int x = keyInt; x != -99; x++) {

                int xIncrease = x + 1;
                NSLog(@"%@",[NSString stringWithFormat:@"xIncrease%d",xIncrease]);
                NSString *tempWHAT = [tempDic objectForKey:[NSString stringWithFormat:@"%d",xIncrease]];
                NSLog(@"tempDic%@",tempDic);
                NSLog(@"tempWhat%@",tempWHAT);
                if ([tempWHAT length] == 0) {
                    NSLog(@"LENGTH WAS 0");

                    x = -100;
                }
                else{

                    NSLog(@"LENGTH WASN'T ZERO, TRYING TO REARRANGE");
                [tempDic setObject: [tempDic objectForKey:[NSString stringWithFormat:@"%d",xIncrease]] forKey:[NSString stringWithFormat:@"%d",x]];
                [tempDic removeObjectForKey:[NSString stringWithFormat:@"%d",xIncrease]];
                }
            }
        }



        //[dict setObject: [dict objectForKey: @"oldkey"] forKey: @"newkey"];
        //[dict removeObjectForKey: @"oldkey"];


        [currentSectionArray removeObjectAtIndex:indexPath.row];
        [[self.sectionArrays objectAtIndex:indexPath.section]isEqualToArray:currentSectionArray];


        [self.mainDictionary setObject:tempDic forKey:[NSString stringWithFormat:@"%@",currentStringSubject]];


        [[NSUserDefaults standardUserDefaults] setObject:self.mainDictionary forKey:[NSString stringWithFormat:@"mainDictionary%@",self.todayString ]];
        [[NSUserDefaults standardUserDefaults]synchronize];

        [tableViews deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];



    }
}

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

        NSLog(@"TEST");


    NSString *currentStringSubject = [self.subjectArray objectAtIndex:indexPath.section];

    NSMutableDictionary *mutDic = [[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"mainDictionary%@",self.todayString ]];

    NSMutableDictionary *tempDir = [mutDic valueForKey:[NSString stringWithFormat:@"%@",[self.subjectArray objectAtIndex:indexPath.section]]];




    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    if ([self.mainDictionary objectForKey:[NSString stringWithFormat:@"%@completed",currentStringSubject]]) {


    }
    [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationNone];

}

1 个答案:

答案 0 :(得分:4)

可能有多种原因但要逐一检查;)

1)确保您必须同时设置

self.tableView.delegate = self;
self.tableView.dataSource = self;

2)并检查此答案(s)

-didSelectRowAtIndexPath: not being called

  

3)如果您使用过任何手势识别器,请尝试将其删除并检查是否会导致问题?

4)

self.tableView.allowsMultipleSelection = NO;
self.tableView.allowsSelection = YES;
相关问题