【问题标题】:UITableView Crashes when scrolling and [reloadData]UITableView 在滚动和 [reloadData] 时崩溃
【发布时间】:2014-01-03 14:41:14
【问题描述】:

我正在使用 theos(越狱)创建一个应用程序,并在我的 RootViewController.mm 文件中的 loadView 方法中创建了一个 UITableView:

- (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

【问题讨论】:

  • 什么是崩溃?堆栈跟踪、调试日志......
  • 我在这里添加了崩溃日志cl.ly/OF9D@DanF
  • 我认为您的崩溃日志没有符号化。缺少方法名称。
  • @BlackRider 我没有使用 Xcode,因为我使用 theos 编译它并将其安装在我的设备上。我使用 Cydia 的 CrashReporter 查看崩溃日志。
  • allKeys 返回的键的顺序是未定义的,您真的不应该使用它来确定节标题的顺序。您可能希望使用这些键创建一个单独的数组并以某种方式对其进行排序,否则您最终可能会导致您的部分偶尔在您身上移动。

标签: iphone objective-c jailbreak uitableview


【解决方案1】:

我发现我需要保留字典,因为它正在发布。所以不是

NSDictionary *countries;

改成这个

@property(nonatomic, retain) NSDictionary *countries;

@synthesize countries;

在您的 .mm 文件中并使用

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

而不是

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

【讨论】:

    【解决方案2】:

    您好,请检查国家/地区是否有任何数据,并且在此行之前的 dic 中是否存在“大陆”值键

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-10
      • 2011-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多