HI Я работаю над проектом на основе UITablview. Мне нравится загружать новый вид, когда когда-либо ячейка получила щелчок. Я использую следующий код в методе делегата didselectRowAtIndexPath. В приведенном ниже кодировании не отображается какая-либо ошибка, но новое представление не получает нагрузку, а [self navigationController] возвращает значение null.возвращение null внутри tableview delegate
внутри Функция 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
@Jordan Я обновил свой вопрос с помощью реального кодирования, можете ли вы его проверить сейчас – Ram