uitableview不响应选择



我有一个我在主视图内添加到UIViewUITableView。该表加载自定义单元格并加载数据并正确响应滚动,但没有调用didSelectRowAtIndexPath。如果我将桌子移到其容器UIView外面,则可以调用delegate方法。

因此,它仅在容器视图内部时才无法工作,但是该视图具有userInteractionEnable = YES,并且表响应滚动。该表也设置为单个选择。

知道为什么它不会响应选择?预先感谢您的任何帮助

这是一些代码:

self.table.delegate = self;
self.table.dataSource = self;

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.classNames count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath
{
    static NSString *MyIdentifier = @"MyIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if(cell == nil)
    {
        [[NSBundle mainBundle] loadNibNamed:@"ClassCell" owner:self options:nil];
        cell = self.tvCell;
        self.tvCell = nil;
    }
    //Set up custom cell
    return cell;
}
//When cell is tapped
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *className = [NSString stringWithFormat:@"%@", [self.classNames objectAtIndex:indexPath.row]];
    if([[AppManager sharedManager] isPad])
    {
        ClassWork *controller = [[ClassWork alloc] initWithNibName:@"ClassWork_iPad" bundle:nil];
        controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        controller.delegate = self;
        [controller setClassIndex:indexPath.row];
        [controller setClassTitle:[NSString stringWithString:className]];
        [self presentModalViewController:controller animated:YES];
    }
    else
    {
        if([[AppManager sharedManager] is4inchScreen])
        {
            ClassWork *controller = [[ClassWork alloc] initWithNibName:@"ClassWork_iPhone4in" bundle:nil];
            controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
            controller.delegate = self;
            [controller setClassIndex:indexPath.row];
            [controller setClassTitle:[NSString stringWithString:className]];
            [self presentModalViewController:controller animated:YES];
        }
        else
        {
            ClassWork *controller = [[ClassWork alloc] initWithNibName:@"ClassWork_iPhone" bundle:nil];
            controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
            controller.delegate = self;
            [controller setClassIndex:indexPath.row];
            [controller setClassTitle:[NSString stringWithString:className]];
            [self presentModalViewController:controller animated:YES];
        }
    }
}
//Delete Cell
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    // If row is deleted, remove it from the list.
    if(editingStyle == UITableViewCellEditingStyleDelete)
    {
        [self.classNames removeObjectAtIndex:indexPath.row];
        [self.classDays removeObjectAtIndex:indexPath.row];
        [self.classTimes removeObjectAtIndex:indexPath.row];
        //Get Corresponding File Path
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,YES);
        NSString *documentsDirectory = [paths objectAtIndex:(0)];
        NSString *classNum = [NSString stringWithFormat:@"Class%d", indexPath.row];
        NSString *classFolder = [documentsDirectory stringByAppendingPathComponent:classNum];
        //Remove Folder
        [[NSFileManager defaultManager] removeItemAtPath: classFolder error: nil];

        //Change numClasses
        NSString *fileName = [documentsDirectory stringByAppendingPathComponent:kNumClasses];
        //Get current number
        NSString *str = [[AppManager sharedManager] loadFileData:fileName];
        int numClasses = [str intValue] - 1;
        //Decrease by 1
        str = [NSString stringWithFormat:@"%d", numClasses];
        //Re-write
        NSData *outFileData = [str dataUsingEncoding:[NSString defaultCStringEncoding]];
        [[AppManager sharedManager] writeFileData:fileName :outFileData];

        //Rename class folders
        NSFileManager *fileMgr = [NSFileManager defaultManager];
        NSString *newFilePath;
        NSString *newClassNum;
        int newIndex = 0;
        for(int i = 0; i < (numClasses + 1); i++)
        {
            classNum = [NSString stringWithFormat:@"Class%d", i];
            classFolder = [documentsDirectory stringByAppendingPathComponent:classNum];
            if([[NSFileManager defaultManager] fileExistsAtPath:classFolder])
            {
                newClassNum = [NSString stringWithFormat:@"Class%d", newIndex];
                newFilePath = [documentsDirectory stringByAppendingPathComponent:newClassNum];
                newIndex++;
                if(classFolder != newFilePath)
                {
                    // Rename the file by moving the file
                    [fileMgr moveItemAtPath:classFolder toPath:newFilePath error:nil];
                }
            }
        }
        //Reload Table
        [self.table reloadData];
        [self setNumberOfAssignmentsToCome];

        if(numClasses == 0)
        {
            self.noClassesLabel1.hidden = NO;
            self.noClassesLabel2.hidden = NO;
            self.table.userInteractionEnabled = NO;
        }
    }
}

事实证明,有一个手势识别器吸吮所有触摸。我将其更改为在某些时间,然后消失了,现在表视图正常工作

最新更新