4

我有一个UITableView添加到UIView主视图内部的。该表加载自定义单元格并加载数据并正确响应滚动,但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;
        }
    }
}
4

1 回答 1

17

原来有一个手势识别器吸收了所有的触摸。我将其更改为在某些时间出现并在其他时间消失,现在表格视图可以正常工作

于 2012-11-09T01:52:05.913 回答