Search code examples
objective-cuitableviewpushviewcontroller

UITableView- tap into the cell and get the next view


I have problems entering a next view in the TableViewController. When I click on the cells i see the NSLog-text, but there is no action and no second view. This means the program enter the methods but does nothing. What is my fault? I am testing around without getting any solution.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.row==0) {
        NSLog(@"Index 0");
        AudioViewController *audioviewcontroller = [[AudioViewController alloc] initWithNibName:@"AudioViewController" bundle:nil];
        [self.navController pushViewController:audioviewcontroller animated:YES];
        [audioviewcontroller release];
        [tableView deselectRowAtIndexPath: indexPath animated:YES];

    }
    if (indexPath.row==1) {
        NSLog(@"Index 1");
        DisplayViewController *displayviewcontroller = [[DisplayViewController alloc] initWithNibName:@"DisplayViewController" bundle:nil];
        [self.navController pushViewController:displayviewcontroller animated:YES];
        [displayviewcontroller release];
        [tableView deselectRowAtIndexPath: indexPath animated:YES];
    }
    if (indexPath.row==2) {
        LichtViewController *lichtviewcontroller = [[LichtViewController alloc] initWithNibName:@"LichtViewController" bundle:nil];
        [self.navController pushViewController:lichtViewController animated:YES];
        [lichtviewcontroller release];
        [tableView deselectRowAtIndexPath: indexPath animated:YES];
        NSLog(@"Index 2");
    }
    if (indexPath.row==3) {
        NSLog(@"Index 3");
        ProjektorViewController *projektorviewcontroller = [[ProjektorViewController alloc] initWithNibName:@"ProjektorViewController" bundle:nil];
        [self.navController pushViewController:projektorviewcontroller animated:YES];
        [tableView deselectRowAtIndexPath: indexPath animated:YES];
        [projektorviewcontroller release];

    }
}

Moreover I tried this code:

UIView *currentView = self.view;    
UIView *theWindow = [currentView superview];
[currentView removeFromSuperview];      
UIView* audioView= audioviewcontroller.view;        
[theWindow addSubview:audioView];       
[self.navController pushViewController:audioviewcontroller animated:YES];       [audioviewcontroller release];
[tableView deselectRowAtIndexPath: indexPath animated:YES]; 

I get no warning but a crash and the debugger console shows:

2011-10-26 10:01:59.344 subview[971:207] -[__NSCFTimer numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x4b44880
2011-10-26 10:01:59.346 subview[971:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFTimer numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x4b44880'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x00dcf5a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x00f23313 objc_exception_throw + 44
    2   CoreFoundation                      0x00dd10bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x00d40966 ___forwarding___ + 966
    4   CoreFoundation                      0x00d40522 _CF_forwarding_prep_0 + 50
    5   UIKit                               0x0047a6ff -[UITableViewRowData(UITableViewRowDataPrivate) _updateNumSections] + 111
    6   UIKit                               0x0047a3b0 -[UITableViewRowData invalidateAllSections] + 66
    7   UIKit                               0x00331d23 -[UITableView(_UITableViewPrivate) _updateRowData] + 113
    8   UIKit                               0x0032d65c -[UITableView noteNumberOfRowsChanged] + 105
    9   UIKit                               0x0033a708 -[UITableView reloadData] + 773
    10  UIKit                               0x00337844 -[UITableView layoutSubviews] + 42
    11  QuartzCore                          0x01d6fa5a -[CALayer layoutSublayers] + 181
    12  QuartzCore                          0x01d71ddc CALayerLayoutIfNeeded + 220
    13  QuartzCore                          0x01d170b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
    14  QuartzCore                          0x01d18294 _ZN2CA11Transaction6commitEv + 292
    15  QuartzCore                          0x01d1846d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
    16  CoreFoundation                      0x00db089b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
    17  CoreFoundation                      0x00d456e7 __CFRunLoopDoObservers + 295
    18  CoreFoundation                      0x00d0e1d7 __CFRunLoopRun + 1575
    19  CoreFoundation                      0x00d0d840 CFRunLoopRunSpecific + 208
    20  CoreFoundation                      0x00d0d761 CFRunLoopRunInMode + 97
    21  GraphicsServices                    0x017261c4 GSEventRunModal + 217
    22  GraphicsServices                    0x01726289 GSEventRun + 115
    23  UIKit                               0x002cdc93 UIApplicationMain + 1160
    24  subview                             0x000023b4 main + 102
    25  subview                             0x00002345 start + 53
    26  ???                                 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'

Thank you for help in advance


Solution

  • Try the codes below if it works for you, this is how I declare my objects/variables in the tableView didSelectRowAtIndexPath. Declare your object (views) at the top of the function

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
     AudioViewController *audioviewcontroller = [[AudioViewController alloc] initWithNibName:@"AudioViewController" bundle:nil];
     DisplayViewController *displayviewcontroller = [[DisplayViewController alloc] initWithNibName:@"DisplayViewController" bundle:nil];
     LichtViewController *lichtviewcontroller = [[LichtViewController alloc] initWithNibName:@"LichtViewController" bundle:nil];
     ProjektorViewController *projektorviewcontroller = [[ProjektorViewController alloc] initWithNibName:@"ProjektorViewController" bundle:nil];
    
     if (indexPath.row==0) {
        NSLog(@"Index 0");
        [self.navController pushViewController:audioviewcontroller animated:YES];
        [audioviewcontroller release];
        [tableView deselectRowAtIndexPath: indexPath animated:YES];
     }
     if (indexPath.row==1) {
        NSLog(@"Index 1");
        [self.navController pushViewController:displayviewcontroller animated:YES];
        [displayviewcontroller release];
        [tableView deselectRowAtIndexPath: indexPath animated:YES];
     }
     if (indexPath.row==2) {
        [self.navController pushViewController:lichtViewController animated:YES];
        [lichtviewcontroller release];
        [tableView deselectRowAtIndexPath: indexPath animated:YES];
        NSLog(@"Index 2");
     }
     if (indexPath.row==3) {
        NSLog(@"Index 3");
        [self.navController pushViewController:projektorviewcontroller animated:YES];
        [tableView deselectRowAtIndexPath: indexPath animated:YES];
        [projektorviewcontroller release];
    
     }
    }