首先,谢谢堆栈溢出。我在这里为我的问题找到了很多解决方案。 我的应用程序有问题它在导航视图控制器之间移动时崩溃了一段时间后。
我的访问不好
Thread 9 Crashed:
0 libsystem_c.dylib 0x365f3096 __abort + 138
1 libsystem_c.dylib 0x365f3006 abort + 122
2 libc++abi.dylib 0x31abbf64 abort_message + 40
3 libc++abi.dylib 0x31ab9346 _ZL17default_terminatev + 18
4 libobjc.A.dylib 0x37fc32dc _objc_terminate + 140
5 libc++abi.dylib 0x31ab93be _ZL19safe_handler_callerPFvvE + 70
6 libc++abi.dylib 0x31ab944a std::terminate() + 14
7 libc++abi.dylib 0x31aba798 __cxa_throw + 116
8 libobjc.A.dylib 0x37fc321c objc_exception_throw + 88
9 CoreFoundation 0x30d73208 -[__NSArrayM insertObject:atIndex:] + 180
10 UIKit 0x32e17abe -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1098
11 UIKit 0x32e1722c -[UITableView layoutSubviews] + 200
12 UIKit 0x32dbbd22 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 142
13 CoreFoundation 0x30d7d224 -[NSObject performSelector:withObject:] + 36
14 QuartzCore 0x324d137a -[CALayer layoutSublayers] + 210
15 QuartzCore 0x324d0f92 CA::Layer::layout_if_needed(CA::Transaction*) + 210
16 QuartzCore 0x324d5114 CA::Context::commit_transaction(CA::Transaction*) + 220
17 QuartzCore 0x324d4e50 CA::Transaction::commit() + 308
18 QuartzCore 0x3251b8ae CA::Transaction::release_thread(void*) + 30
19 libsystem_c.dylib 0x365ad6c8 _pthread_tsd_cleanup + 164
20 libsystem_c.dylib 0x365ad344 _pthread_exit + 116
21 libsystem_c.dylib 0x365bf5c4 pthread_exit + 24
22 Foundation 0x37e40384 +[NSThread exit] + 4
23 Foundation 0x37ec45b8 __NSThread__main__ + 1072
24 libsystem_c.dylib 0x365bbc16 _pthread_start + 314
25 libsystem_c.dylib 0x365bbad0 thread_start + 0
rootViewController.m中的代码
//
// RootViewController.m
// Q8f
//
// Created by Abdulaziz Hamdan on 10/26/11.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
#import "RootViewController.h"
#import "SubCategoryViewController.h"
#import "DestorViewController.h"
@implementation RootViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"RootView", @"First");
self.tabBarItem.image = [UIImage imageNamed:@"first"];
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
-(void)dealloc{
self.tableView.delegate = nil;
self.tableView.dataSource = nil;
[category release];
[cid release];
category = nil;
cid = nil;
[super dealloc];
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
if ([[UINavigationBar class]respondsToSelector:@selector(appearance)]) {
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar2.png"] forBarMetrics:UIBarMetricsDefault];
}
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"back.png"]];
category = [[NSMutableArray alloc] init];
cid = [[NSMutableArray alloc] init];
[category addObject:@"a"];
[category addObject:@"b"];
[category addObject:@"c"];
[category addObject:@"d"];
[category addObject:@"e"];
[category addObject:@"f"];
[category addObject:@"g"];
[category addObject:@"h"];
[cid addObject:@"1"];
[cid addObject:@"2"];
[cid addObject:@"3"];
[cid addObject:@"4"];
[cid addObject:@"5"];
[cid addObject:@"6"];
[cid addObject:@"7"];
[cid addObject:@"8"];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [category count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
/* UIView *backView = [[UIView alloc] initWithFrame:CGRectZero];
backView.backgroundColor = [UIColor clearColor];
cell.backgroundColor = [UIColor clearColor];
cell.backgroundView = backView;
[backView release];
*/
// cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
cell.textLabel.text = [category objectAtIndex:indexPath.row];
[[cell textLabel] setTextAlignment:UITextAlignmentCenter];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row > 0) {
SubCategoryViewController *SubCategoryView = [[[SubCategoryViewController alloc] initWithNibName:@"SubCategoryViewController" bundle:nil] autorelease];
SubCategoryView.title = [category objectAtIndex:indexPath.row];
SubCategoryView->cid = [cid objectAtIndex:indexPath.row];
[self.navigationController pushViewController:SubCategoryView animated:NO];
}else{
DestorViewController *DestorView = [[[DestorViewController alloc] initWithNibName:@"DestorViewController" bundle:nil] autorelease];
DestorView.title = [category objectAtIndex:indexPath.row];
[self.navigationController pushViewController:DestorView animated:NO];
}
}
@end
SubCategoryViewController.m中的
//
// SubCategoryViewController.m
// Q8f
//
// Created by Abdulaziz Hamdan on 10/26/11.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
#import "SubCategoryViewController.h"
@implementation SubCategoryViewController
@synthesize cid;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
-(void)dealloc{
self.tableView.delegate = nil;
self.tableView.dataSource = nil;
[cid release];
cid = nil;
[xmlParser release];
[subCate release];
[hud release];
hud.delegate = nil;
xmlParser = nil;
subCate = nil;
[super dealloc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
xmlParser = [[XMLParser alloc] init];
subCate = [[subCategory alloc] init];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"back.png"]];
[NSThread detachNewThreadSelector:@selector(startmethod) toTarget:self withObject:nil];
[self performSelectorOnMainThread:@selector(startIt) withObject:nil waitUntilDone:FALSE];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)myTask {
// Do something usefull in here instead of sleeping ...
// Labels can be changed during the execution
//HUD.detailsLabelText = @"Something";
//sleep(3);
}
-(void)stopIt{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[hud hide:YES];
cid = nil;
}
-(void)startmethod {
[xmlParser loadXMLByURL:cid];
[self.tableView reloadData];
[self stopIt];
}
-(void)startIt{
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
hud = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:hud];
hud.delegate = self;
hud.labelText = @"loading";
[hud show:YES];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [[xmlParser list] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
subCate = [[xmlParser list] objectAtIndex:indexPath.row];
cell.textLabel.text = [subCate name];
// cell.textLabel.numberOfLines = 5; //Change this value to show more or less lines.
cell.textLabel.textAlignment = UITextAlignmentRight;
//[[cell textLabel] setTextAlignment:UITextAlignmentCenter];
//cell.selectionStyle = UITableViewCellSelectionStyleGray;
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
subCate = [[xmlParser list] objectAtIndex:indexPath.row];
if ([[subCate father] isEqualToString:@"1"]) {
SubCategoryViewController *SubCategoryView = [[[SubCategoryViewController alloc] initWithNibName:@"SubCategoryViewController" bundle:nil] autorelease];
SubCategoryView.title = [subCate name];
SubCategoryView->cid = [subCate cid];
[self.navigationController pushViewController:SubCategoryView animated:NO];
}else{
EntryViewController *EntryView = [[[EntryViewController alloc] initWithNibName:@"EntryViewController" bundle:nil] autorelease];
EntryView.title = [subCate name];
EntryView->cid = [subCate cid];
[self.navigationController pushViewController:EntryView animated:NO];
}
}
@end
我希望在这里找到解决方案。 提前谢谢。
答案 0 :(得分:0)
从你的堆栈跟踪中我猜你已经通过在UIViewController的实时循环中使用错误的方法释放了一些视图。
但没有代码,这只是猜测。
这有用吗? SubCategoryView->cid = [cid objectAtIndex:indexPath.row];
你在SubCategoryView上有一个属性,即合成cid,为什么不使用:
SubCategoryView.cid = [cid objectAtIndex:indexPath.row];
我知道->
是一个对结构进行操作的有效运算符,但SubCategoryView是一个类,我不是该运算符的专家,但您是否尝试将其转换为属性调用?