2011-02-10 109 views
2

希望有人能幫助我。單擊「後退」按鈕時,UINavigationController應用程序崩潰

didSelectRowAtIndexPath方法中,我正在加載和推送詳細視圖控制器,當您點擊詳細視圖中的「後退」按鈕返回到根視圖時,應用程序將崩潰。沒有錯誤日誌或任何東西。

我95%確定它有一些事情要做的「遊樂設施」對象被釋放得太早,但無法弄清楚。

感謝您的幫助!

#import "RidesViewController.h" 
#import "RideDetailViewController.h" 
#import "JSON.h" 

@implementation RidesViewController 
@synthesize rides; 

#pragma mark - 
#pragma mark View lifecycle 
- (void)viewDidLoad { 

    [super viewDidLoad]; 

    self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"table-view-background.png"]]; 

    rides       = [[NSDictionary alloc] init]; 

    NSString  *filePath  = [[NSBundle mainBundle] pathForResource:@"rides" ofType:@"JSON"]; 
    NSData   *jsonData  = [NSData dataWithContentsOfFile:filePath]; 
    NSString  *responseString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; 

    NSDictionary *results  = [responseString JSONValue]; 

    rides       = [results objectForKey:@"rides"]; 

    [rides retain]; 
} 

#pragma mark - 
#pragma mark Table view data source 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 

    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

    return [rides 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]; 

    cell.textLabel.text  = [[rides valueForKey:@"title"] objectAtIndex:indexPath.row]; 
    cell.accessoryType  = UITableViewCellAccessoryDisclosureIndicator; 

    return cell; 
} 

#pragma mark - 
#pragma mark Table view delegate 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    RideDetailViewController *rideDetailViewController = [[RideDetailViewController alloc] initWithNibName:@"RideDetailViewController" bundle:nil]; 

    NSString  *aTitle   = [[NSString alloc] initWithString:[[rides valueForKey:@"title"] objectAtIndex:indexPath.row]]; 
    NSString  *aImagePath  = [[NSString alloc] initWithString:[[rides valueForKey:@"imagePath"] objectAtIndex:indexPath.row]]; 
    NSString  *aDescription = [[NSString alloc] initWithString:[[rides valueForKey:@"description"] objectAtIndex:indexPath.row]]; 
    NSString  *aVideoPath  = [[NSString alloc] initWithString:[[rides valueForKey:@"videoPath"] objectAtIndex:indexPath.row]]; 

    [rideDetailViewController initWithTitle:aTitle imagePath:aImagePath description:aDescription videoPath:aVideoPath]; 

    [self.navigationController pushViewController:rideDetailViewController animated:YES]; 

    [rideDetailViewController release]; 
    [aTitle      release]; 
    [aImagePath     release]; 
    [aDescription    release]; 
    [aVideoPath     release]; 
} 

#pragma mark - 
#pragma mark Memory management 
- (void)didReceiveMemoryWarning { 

    [super didReceiveMemoryWarning]; 
} 

- (void)dealloc { 
    [super dealloc]; 
} 


@end 
+2

當你的開發版本的應用程序崩潰,立即打開調試器,看看哪一行代碼導致崩潰。然後張貼這段代碼在這裏,我們可以幫助你......... – Satyam

回答

1

定義您NSString的在你的頭,然後將它們放置在cellForRowAtIndexPath:

+0

哪些NSString?aTitle,aImagePath等等或者viewDidLoad中的filePath字符串?我不能在didSelectRowAtIndexPath中使用NSString,因爲我需要indexPath.row變量。 –

+0

其實,在你的'cellForRowAtIndexPath:'委託中嘗試它們。 – WrightsCS

+0

Awesome這是有效的,我唯一需要做的就是保留每個NSString,而且我還必須添加[self。 tableView reloadData]放在viewDidAppear方法中。 –

1

viewwillapper方法只是剪切從viewdidload粘貼整個事情。

+0

已經嘗試過那個:(仍然崩潰。 –

+0

可能我有你的崩潰日誌? – GameLoading

+0

沒有崩潰日誌,它只是崩潰。 –

相關問題