iphone – returning null inside tableview delegate – Education Career Blog

HI
I am working on UITablview based project. i like to load a new view when ever a cell got click. i am using following code in didselectRowAtIndexPath delegate method.
The below coding is not showing any error but new view not get load and self navigationController is returning null.

inside Viewdidload function self navigationcontroller returning proper value. but inside Delegate method self navigationcontroller returns null.

  /// inside appDelegate class
      - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

// Override point for customization after application launch.

self.viewController = LAMainViewController_iPhone allocinitWithNibName:@"LAMainViewController_iPhone" bundle:nil;

UINavigationController *controller = UINavigationController allocinitWithRootViewController:viewController;

window addSubview:controller.view;

controller release;

window makeKeyAndVisible;

return YES;
}




  /// inside LAmainviewcontroller.m


    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {

if ((self = super initWithNibName:nibNameOrNil bundle:nibBundleOrNil)) {

    // Custom initialization
    }

//self.navigationController.navigationBar.backgroundColor =UIColor clearColor;// [email protected]"test";

return self;
     }



       - (void)viewDidLoad {

    super viewDidLoad;

     NSString *materialPlistPath = NSBundle mainBundlepathForResource:@"materials" ofType:@"plist";

materialList = NSArray allocinitWithContentsOfFile:materialPlistPath;

materialTable.backgroundColor = UIColor blackColor;

NSLog(@" dud kiad navigationController  %@", self.navigationController);

//2010-10-20 15:22:03.809 LabAssistant17368:207  dud kiad navigationController  <UINavigationController: 0x5f3b160>

   }

    -(void)viewWillAppear:(BOOL)animated{

super viewWillAppear:YES;

self.navigationController.navigationBarHidden = YES;

NSIndexPath *indexPath = materialTable indexPathForSelectedRow;

materialTable deselectRowAtIndexPath:indexPath animated:YES;

    }





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

  LAMaterialPropertiesViewController_iPhone *materialPropertyListView = LAMaterialPropertiesViewController_iPhone alloc initWithNibName:@"LAMaterialPropertiesViewController_iPhone" bundle:nil autorelease;

  materialPropertyListView.chemicalName = materialList objectAtIndex:indexPath row objectForKey:@"materialProperty";

  self navigationController pushViewController:materialPropertyListView animated:YES;
  NSLog(@"%@",self navigationController);

 ///2010-10-20 16:20:42.634 LabAssistant17656:207  navigationController  (null)
 }

please help me to fix this issue.
thanks!

,

Remove the autorelease from the init statement. Actually the viewcontroller is getting released before it gets pushed.

instead of

LAMaterialPropertiesViewController_iPhone *materialPropertyListView = LAMaterialPropertiesViewController_iPhone alloc initWithNibName:@"LAMaterialPropertiesViewController_iPhone" bundle:nil autorelease;

try this

LAMaterialPropertiesViewController_iPhone *materialPropertyListView = LAMaterialPropertiesViewController_iPhone alloc initWithNibName:@"LAMaterialPropertiesViewController_iPhone" bundle:nil;

Hope this will solve your problem.

,

I think the table view delegate is called before the navigation controller is set to the view controller.

Can you try reloading the tableview tableview reloadData; in viewWillAppear or viewDidAppear?

Leave a Comment