有些人可以解释如何适当地继承UIViewController,然后将其加载到窗口中而不使用一个笔尖。有人可以解释正确的方法来分类一个UIViewController
我是否需要设置视图以及何时执行该操作?的loadView?
当我使用我的customUIViewController子类时,我的应用程序崩溃。一切加载了找,直到我点击一个按钮,它孔潘关于“错误访问”
GettingStarted *vc = [[GettingStarted alloc] init];
UISplitViewController *split = self.splitViewController;
NSArray *vcArray = split.viewControllers;
NSLog(@"viewcontroll cout:%d", vcArray.count);
// this line of code crashes my app. I fi comment it out everything works fine
UINavigationController *detailViewController = (UINavigationController*)[vcArray objectAtIndex:1];
//
detailViewController pushViewController:vc animated:YES];
[vc release];
GettingStarted.m
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationItem setHidesBackButton:YES animated:YES];
//UIView *baseView = [[UIView alloc] init];
[[self navigationItem] setTitle:@"Getting Started"];
UIImageView *noUsersIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"no_users.png"]];
[noUsersIV setFrame:CGRectMake(0.0f, 0.0f, 466, 961.0f)];
[noUsersIV setHidden:NO];
[noUsersIV setTag:1006];
[[self view] addSubview:noUsersIV];
[noUsersIV release];
UIButton *btnAddUser = [UIButton buttonWithType:UIButtonTypeCustom];
[btnAddUser setImage:[UIImage imageNamed:@"no_users_button_standard.png"] forState:UIControlStateNormal];
[btnAddUser setImage:[UIImage imageNamed:@"no_users_button_activated.png"] forState:UIControlStateSelected];
[btnAddUser addTarget:self action:@selector(addUser:) forControlEvents:UIControlEventTouchUpInside];
[btnAddUser setFrame:CGRectMake(0, 428,466, 124)];
[[self view] addSubview:btnAddUser];
[btnAddUser release];
//self.view = baseView;
//[baseView release];
}
它抱怨“访问不良”,因为你搞砸了你的内存管理的地方。看看GDB的回溯,看看崩溃发生的位置。这会给你一个强大的线索,你什么对象,你忘了保留/过度发布。 – 2010-11-10 05:37:02
太细节。如果你可以看到视图和按钮,那么你可能在正确的地方创建了一些东西(loadView),但是在一个对象上的保留计数很差。发布您的loadView代码。 – 2010-11-10 05:39:56
更新了帖子。如果我注释掉我抓住UINavigationController的行,那么一切正常 – Arcadian 2010-11-10 05:54:28