2011-11-11 21 views
0

まず、スタックオーバーフローのおかげです。私はここで私の問題のための多くの解決策を見つけました。 私はナビゲーションビューコントローラ間を移動中にクラッシュしている私のアプリに問題があります一定の期間の後。ナビゲーションコントローラのviewcontrollersの切り替え中にクラッシュしましたか?

私はここで解決策を見つけることを願っています悪いアクセス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 

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 

を得ました。ありがとうございます。

+0

エラーコードを投稿してください。 –

+0

いくつかのコードは間違いなく助けになるでしょう... –

+0

あなたは私たちにいくつかの洞察力を与えるために相対コードを掲示すべきです。 – samfisher

答えて

0

スタックトレースから、UIViewControllerのライブサイクルの間違ったメソッドでリリースすることによって、いくつかのビューを解放したと思います。

コードなしでこれはちょうど推測です。


それは機能していますか? SubCategoryView->cid = [cid objectAtIndex:indexPath.row]; あなたは合成CIDが、なぜ使用しないことをSubCategoryViewのプロパティを持っている:
SubCategoryView.cid = [cid objectAtIndex:indexPath.row];

を私は->構造を操作するための有効な演算子ですが、SubCategoryViewがクラスである知っている、私はそれで何の専門家ですあなたはそれをプロパティ呼び出しに変換しようとしましたか?

+0

私は上記のコードを投稿しました –

+0

はいそれは最後のxcodeバージョンで動作しています –

関連する問題