2013-04-12 139 views
2

我創建使用THEOS(越獄)一個應用程序,我已經在我的RootViewController.mm文件創建在loadView方法一個UITableView:UITableView的崩潰[reloadData]

- (void)loadView { 
    self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]; 
    self.view.backgroundColor = [UIColor redColor]; 



    NSError * error; 
    NSArray * directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/var/mobile/Library/BannerImage" error:&error]; 

    countries = [NSDictionary dictionaryWithObject:directoryContents forKey:@"Themes"]; 
    mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 480) style:UITableViewStyleGrouped]; 

    [mainTableView setDataSource:self]; 
    [mainTableView setDelegate:self]; 
    [self.view addSubview:mainTableView]; 
} 

而其餘的我的代碼:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return [countries count]; 
} 

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{ 
    return [[countries allKeys] objectAtIndex:section]; 
} 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    NSString *continent = [self tableView:tableView titleForHeaderInSection:section]; 
    return [[countries valueForKey:continent] 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]; 
    } 
     // Configure the cell... 

    NSString *continent = [self tableView:tableView titleForHeaderInSection:indexPath.section]; 
    NSString *country = [[countries valueForKey:continent] objectAtIndex:indexPath.row]; 

    cell.textLabel.text = country; 

    cell.accessoryType = UITableViewCellAccessoryNone; 
    if([self.checkedIndexPath isEqual:indexPath]) 
    { 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
    } 
    else 
    { 
     cell.accessoryType = UITableViewCellAccessoryNone; 
    } 
    return cell; 
} 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 


    UITableViewCell *object = [tableView cellForRowAtIndexPath:indexPath]; 
    [object setSelected:NO animated:YES]; 
    NSString *selectedTheme = [[object textLabel] text]; 

    NSDictionary *plistFile = [NSDictionary dictionaryWithObject:selectedTheme forKey:@"CurrentTheme"]; 
    [plistFile writeToFile:@"/Applications/BannerImage.app/CurrentTheme.plist" atomically:YES]; 

    if(self.checkedIndexPath) 
    { 
     UITableViewCell* uncheckCell = [tableView 
             cellForRowAtIndexPath:checkedIndexPath]; 
     uncheckCell.accessoryType = UITableViewCellAccessoryNone; 
    } 
    UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath]; 
    cell.accessoryType = UITableViewCellAccessoryCheckmark; 
    self.checkedIndexPath = indexPath; 
} 

它崩潰時,我向上滾動,並儘量向後向下滾動,它崩潰時[mainTableView reloadData]被調用。我怎樣才能解決這個問題? Crash Log

+0

什麼是飛機墜毀前提出或不DIC?堆棧跟蹤,調試日誌.... –

+0

我在這裏添加了一個崩潰日誌http://cl.ly/OF9D @DanF – atomikpanda

+0

我認爲你的崩潰日誌不是象徵性的。方法名稱丟失。 – Macondo2Seattle

回答

2

我發現我需要保留字典,因爲它被釋放。因此,而不是

NSDictionary *countries; 

改變這種

@property(nonatomic, retain) NSDictionary *countries; 

@synthesize countries; 
在.mm文件

和使用

self.countries = [NSDictionary dictionaryWithObject:directoryContents forKey:@"Themes"]; 

,而不是

countries = [NSDictionary dictionaryWithObject:directoryContents forKey:@"Themes"]; 
0

嗨,請檢查是否有在國家的任何數據和「大陸」值鍵此行

NSString *country = [[countries valueForKey:continent] objectAtIndex:indexPath.row];