我从一个连接到nib的UIViewController的教程示例开始,但现在我决定以编程方式完成所有操作。因此,我删除了笔尖,但不知道如何实现我的控制器。
我做了类似的事情:
EventsDetailController *myChild = [[EventsDetailController alloc] init];
[self.navigationController pushViewController:myChild animated:YES];
但是,单击特定单元格时崩溃。
我必须使用initWith吗?在我有一个笔尖之前,它是initWithNib
#import <UIKit/UIKit.h>
@interface EventsDetailController : UIViewController {
NSString *message;
}
@property (nonatomic, copy) NSString *message;
@end
#import "EventsDetailController.h"
@implementation EventsDetailController
@synthesize message;
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
}
-(void)viewDidLoad{
UILabel *theMsg = [[UILabel alloc] initWithFrame:CGRectMake(0,0,200,30)];
theMsg.text = @"hello";
[theMsg release];
[super viewDidLoad];
}
-(void)viewDidUnload{
self.message = nil;
[super viewDidUnload];
}
-(void)dealloc{
[message release];
[super dealloc];
}
@end
也许,我会从头开始,我认为它仍在寻找我删除的笔尖。
答案 0 :(得分:0)
我假设您已将应用委托的window.rootViewController
设置为NavigationController
个实例,并且该实例是使用initWithRootViewController
创建的,正如您提到的那样,您正在访问单击一个单元格时崩溃的点。
查看添加的代码,我看到的唯一奇怪的是'veiwDidLoad'方法 - 你分配并释放'theMsg',但不要使用它。我假设你为了简洁而删除了一些代码。
当我离开.nib文件(开始我的第一个iPhone应用程序后大约5分钟)时,我最终从头开始。我会继续使用它,一次添加一点功能。