【发布时间】:2010-02-13 19:54:55
【问题描述】:
我有一个 NSArray,它被填充到我的 UITableViewController 的 init 方法中。
我在“didSelectRowAtIndexPath”中使用这个对象来推送另一个tableviewcontroller。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ablogSingleCatTableViewController *singleCatTableViewController = [[ablogSingleCatTableViewController alloc] initWithStyle:UITableViewStylePlain category:[categories objectAtIndex:indexPath.row]];
[[self navigationController] pushViewController:singleCatTableViewController animated:YES];
[singleCatTableViewController release];
}
当我启动我的应用程序时,这会工作几次。选择一行并在一个随机点返回主 uitableview 控制器后,我的应用程序在选择一行后崩溃。
我发现了一些 nslog,如果我尝试使用我的“类别”对象,它会崩溃。
所以
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"before");
NSLog(@"cats: %@", categories);
NSLog(@"after");
ablogSingleCatTableViewController *singleCatTableViewController = [[ablogSingleCatTableViewController alloc] initWithStyle:UITableViewStylePlain category:[categories objectAtIndex:indexPath.row]];
[[self navigationController] pushViewController:singleCatTableViewController animated:YES];
[singleCatTableViewController release];
}
使用该代码,我的应用程序在“之前”之后崩溃......“之后”永远不会出现。 我不知道为什么我的“类别”对象会导致我的应用程序崩溃?!
我的类别对象在我的头文件中定义并且有一个@property(非原子,保留)。我合成它并在我的 dealloc 方法中释放它。
有人有想法吗?
// 编辑:
这里有更多细节,因为 cmets:
调试器控制台说:“程序收到信号:“EXC_BAD_ACCESS”。
我这样创建类别数组:
- (void)initCategories {
NSString *path = [[NSBundle mainBundle] pathForResource:@"Categories" ofType:@"plist"];
[self setCategories:[[NSArray alloc] initWithContentsOfFile:path]];
}
在我的 initwithstyle 方法中调用此方法
[self initCategories];
我的其他自定义初始化方法如下所示:
- (id)initWithStyle:(UITableViewStyle)style category:(NSDictionary*)cat {
if (self = [super initWithStyle:style]) {
currentCategory = cat;
items = [[NSMutableArray alloc] init];
self.title = [currentCategory objectForKey:@"TITLE"];
//XLog("%@", currentCategory);
}
return self;
}
【问题讨论】:
-
您能否提供有关崩溃的更多详细信息?如果您调试应用程序而不仅仅是运行它(cmd-Y 与 cmd-R),您通常会让调试器在崩溃点暂停执行。这样您就可以检查确切的回溯并查看当时任何实例变量的值。
-
请显示您创建类别数组的代码
-
我认为您在 ablogSingleCatTableViewController initWithStyle:category: 方法中存在问题。你能发布你的代码吗?
-
我编辑了我的第一篇文章。看看有没有帮助=(
标签: iphone objective-c cocoa-touch