I have a UITableView that I added to a UIView inside the main view. The table loads the user cell and loads the data and responds correctly to scrolling, but didSelectRowAtIndexPath not called. If I move the table outside of its UIView container, the delegate method is called.
So this does not work when inside the container view, but this view has userInteractionEnable = YES and the table responds to scrolling. The table is also set to one choice.
Any idea why she won't answer the choice? Thanks in advance for any help
Here is the code:
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; } } }
source share