HI 我正在開發基於UITablview的項目。當單元格點擊時,我喜歡加載新視圖。我在didselectRowAtIndexPath委託方法中使用以下代碼。 下面的代碼沒有顯示任何錯誤,但新視圖沒有得到加載,[self navigationController]返回null。在tableview委託中返回null
裏面Viewdidload函數[self navigationcontroller]返回適當的值。但是在Delegate方法[self navigationcontroller]中返回null。
/// inside appDelegate class
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.viewController = [[LAMainViewController_iPhone alloc]initWithNibName:@"LAMainViewController_iPhone" bundle:nil];
UINavigationController *controller = [[UINavigationController alloc]initWithRootViewController: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 mainBundle]pathForResource:@"materials" ofType:@"plist"];
materialList = [[NSArray alloc]initWithContentsOfFile:materialPlistPath];
materialTable.backgroundColor = [UIColor blackColor];
NSLog(@" dud kiad navigationController %@", self.navigationController);
//2010-10-20 15:22:03.809 LabAssistant[17368: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 LabAssistant[17656:207] navigationController (null)
}
請幫我解決這個問題。 謝謝!
沒有足夠的信息來幫助你。代碼看起來很好。是否有錯誤訊息?如果不是,則發佈所有代碼。 – Jordan 2010-10-20 10:59:29
@Jordan我已經用真正的編碼更新了我的問題,你現在可以檢查它 – Ram 2010-10-20 11:10:57