2013-04-12 258 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];