Iphone UITableView不响应选择

Iphone UITableView不响应选择,iphone,objective-c,ios,uitableview,Iphone,Objective C,Ios,Uitableview,我在主视图中添加了一个UITableView。该表加载自定义单元格并加载数据并正确响应滚动,但未调用didSelectRowAtIndexPath。如果我将表移动到其容器UIView之外,将调用delegate方法 因此,它仅在容器视图中不起作用,但该视图具有userInteractionEnable=YES,并且表响应滚动。 该表也设置为单选 你知道为什么它对选择没有反应吗? 提前谢谢你的帮助 下面是一些代码: self.table.delegate = self; self.table.da

我在主视图中添加了一个
UITableView
。该表加载自定义单元格并加载数据并正确响应滚动,但未调用
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;
        }
    }
}
self.table.delegate=self;
self.table.dataSource=self;
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
返回1;
}
//自定义表视图中的行数。
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
返回[self.classNames count];
}
//自定义表格视图单元格的外观。
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*MyIdentifier=@“MyIdentifier”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
如果(单元格==nil)
{
[[NSBundle mainBundle]loadNibNamed:@“ClassCell”所有者:自选项:nil];
cell=self.tvCell;
self.tvCell=nil;
}
//设置自定义单元格
返回单元;
}
//当电池被点击时
-(void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath
{
NSString*className=[NSString stringWithFormat:@“%@,[self.classNames objectAtIndex:indexath.row]];
如果([[AppManager sharedManager]isPad])
{
ClassWork*controller=[[ClassWork alloc]initWithNibName:@“ClassWork\u iPad”bundle:nil];
controller.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
controller.delegate=self;
[控制器setClassIndex:indexath.row];
[控制器setClassTitle:[NSString stringWithString:className]];
[self-presentModalViewController:控制器已设置动画:是];
}
其他的
{
如果([[AppManager sharedManager]是4inchscreen])
{
ClassWork*controller=[[ClassWork alloc]initWithNibName:@“ClassWork\u iPhone4in”捆绑包:nil];
controller.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
controller.delegate=self;
[控制器setClassIndex:indexath.row];
[控制器setClassTitle:[NSString stringWithString:className]];
[self-presentModalViewController:控制器已设置动画:是];
}
其他的
{
ClassWork*controller=[[ClassWork alloc]initWithNibName:@“ClassWork\u iPhone”bundle:nil];
controller.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
controller.delegate=self;
[控制器setClassIndex:indexath.row];
[控制器setClassTitle:[NSString stringWithString:className]];
[self-presentModalViewController:控制器已设置动画:是];
}
}
}
//删除单元格
-(void)tableView:(UITableView*)tableView提交的编辑样式:(UITableViewCellEditingStyle)行的编辑样式索引路径:(NSIndexPath*)索引路径
{
//如果删除了行,请将其从列表中删除。
如果(editingStyle==UITableViewCellEditingStyleDelete)
{
[self.classNames removeObjectAtIndex:indexath.row];
[self.classDays removeObjectAtIndex:indexath.row];
[self.classTimes removeObjectAtIndex:indexath.row];
//获取相应的文件路径
NSArray*Path=NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,是);
NSString*documentsDirectory=[paths objectAtIndex:(0)];
NSString*classNum=[NSString stringWithFormat:@“类%d”,indexath.row];
NSString*classFolder=[DocumentsDirectoryStringByAppendingPathComponent:classNum];
//删除文件夹
[[NSFileManager defaultManager]removeItemAtPath:classFolder错误:nil];
//更换numClasses
NSString*fileName=[DocumentsDirectoryStringByAppendingPathComponent:kNumClasses];
//获取当前号码
NSString*str=[[AppManager sharedManager]加载文件数据:文件名];
int numclass=[str intValue]-1;
//减少1
str=[NSString stringWithFormat:@“%d”,numclass];
//重写
NSData*outFileData=[str DATAUSINGENCODE:[NSString defaultCStringEncoding]];
[[AppManager sharedManager]writeFileData:fileName:outFileData];
//重命名类文件夹
NSFileManager*fileMgr=[NSFileManager defaultManager];
NSString*newFilePath;
NSString*newClassNum;
int newIndex=0;
对于(int i=0;i<(numclass+1);i++)
{
classNum=[NSString stringWithFormat:@“类%d”,i];
classFolder=[DocumentsDirectoryStringByAppendingPathComponent:classNum];
if([[NSFileManager defaultManager]fileExistsAtPath:classFolder])
{
newClassNum=[NSString stringWithFormat:@“类%d”,newIndex];
newFilePath=[DocumentsDirectoryStringByAppendingPathComponent:newClassNum];
newIndex++;
if(classFolder!=newFilePath)
{
//通过移动文件重命名文件
[fileMgr moveItemAtPath:classFolder toPath:newFilePath错误:nil];
}
}
}
//重新加载表
[self.table reloadData];
[自行设置待分配的编号];
如果(numClasses==0)
{
self.noClassesLabel1.hidden=否;
self.noClassesLabel2.hidden=否;
self.table.userInteractionEnabled=否;
}
}
}
结果是有一个