UITableView没有响应选择

时间:2012-10-28 04:00:19

标签: iphone objective-c ios uitableview

我在主视图中添加了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;
        }
    }
}

1 个答案:

答案 0 :(得分:17)

原来,有一个手势识别器吸收了所有的触摸。我在某些时候将它改为在那里并且离开了其他人,现在桌面视图正常工作