gpt4 book ai didi

iphone - UITableView 滚动时崩溃并且 [reloadData]

转载 作者:行者123 更新时间:2023-12-03 21:02:03 24 4
gpt4 key购买 nike

我正在使用 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

最佳答案

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

NSDictionary *countries;

改成这个

@property(nonatomic, retain) NSDictionary *countries;

@synthesize countries;

在您的 .mm 文件中并使用

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

而不是

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

关于iphone - UITableView 滚动时崩溃并且 [reloadData],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15979259/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com