gpt4 book ai didi

ios - scrollToRowAtIndexPath 在发布版本中停止滚动但在调试版本中工作

转载 作者:行者123 更新时间:2023-11-29 02:47:51 25 4
gpt4 key购买 nike

我有一个非常奇怪的案例,我想听听您的意见。在我的应用程序中,我有 scrollToRowAtIndexPath 以便在侧面索引上使用选项卡时,它会跳转到单元格。直到大约 3 个月前,它一直运行良好,相同的函数调用在所有版本中都不再滚动。我使用相同的 XCode 版本,相同的代码,但它停止滚动到单元格。我发现如果我在 XCode 中运行该应用程序(即调试版本),滚动将起作用。但如果我构建版本,它不会滚动。这很令人费解。

我什至尝试重新编译我在 3 月份发布的完全相同的应用程序代码,旧版本会滚动,但我现在重新编译的版本不会滚动。

有没有人遇到类似的问题,即发布版本的行为与调试版本不同。在不同时间构建的版本(三月份的旧版本,现在的新版本)会表现不同吗?我原以为 XCode 5.1 中可能存在错误(但它与我在三月份编译旧版本和昨天重新编译的版本时使用的版本相同)。我更新到 XCode 5.1.1,这是同样的问题。

我迷路了,因为这非常非常奇怪~

这是三月份和现在没有更改的代码。

// Section Index Array
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
NSMutableArray *charactersForSort = [[NSMutableArray alloc] init];
for (NSDictionary *item in self.tableViewArray)
{
if (![charactersForSort containsObject:[[item valueForKey:@"name"] substringToIndex:1]])
{
[charactersForSort addObject:[[item valueForKey:@"name"] substringToIndex:1]];
}
}
return charactersForSort;
}

// Section Index scrolling jump
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
BOOL found = NO;
NSInteger b = 0;

for (NSDictionary *item in self.tableViewArray)
{
if ([[[item valueForKey:@"name"] substringToIndex:1] isEqualToString:title])
{
if (!found)
{
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:b inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
found = YES;
}
}
b++;
}
}

这段在构建版本中编译的代码以前可以工作大约一年,但不久前就停止工作了。并且这段代码在 XCode 中运行时始终有效。

编辑

我现在知道问题出在编译器优化上。不知何故,“最快,最小”优化会导致这种类型的索引滚动不起作用。我仍然不明白为什么它以前有效,因为我从未更改过优化设置。

最佳答案

使用[self.tableView scrollRectToVisible:newRectFrame animated:NO];代替[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:b inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];

关于ios - scrollToRowAtIndexPath 在发布版本中停止滚动但在调试版本中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24888475/

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