IOS6中的内存分配差异?(Memory allocation differences in IOS6?)

编程入门 行业动态 更新时间:2024-10-25 14:26:32
IOS6中的内存分配差异?(Memory allocation differences in IOS6?)

自从我在iPhone 4上更新了我的iOS软件后,我正在开发的应用程序开始出现滞后现象。 这只发生在我向UISearchField提供输入时。

当我在iOS键盘上点击大约30个字母时会出现“滞后”。 在此之后,每次连续敲击都会落后,让人觉得手机本身无法再处理输入。

我有一个UISearchDisplayController,只要我在搜索字段中输入三个或更多字母,就会选择我的数据库。

这是一些代码。

实际搜索

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { if ([searchText length] >= 3) { if (searchObject != nil) { searchObject = nil; searchObject = [[FritextSok alloc]init]; [searchObject setDelegate:self]; } [searchObject setSearchstring:searchText]; [searchObject search]; } else { // Displays non filtered results. } }

我在运行iOS6模拟器时也遇到了这种情况。

另外,除了iOS键盘“滞后”。 每个UISegmentedControl,在不同的视图控制器中似乎都需要FOREVER绘制。 键盘混搭后会发生这种情况。

我正在重复使用单元格(我认为)并且没有实际的想法是什么导致了这一点,因为它似乎在从4.3到5.1的所有iOS版本上运行完美。

我尝试过不同的方法来分配searchObject。 似乎没有任何帮助。

编辑

这是一个偶尔出现的错误消息

purgeIdleCellConnections: found one to purge conn = <Memory address>

编辑2

使用PROFILER工具进行了一些试验和错误。 我发现由于这个阻滞,生活记忆不断增加。

UISegmentedControl *segment = [[UISegmentedControl alloc] init]; segment.frame = CGRectMake(0, 0, 70, 32); segment.selectedSegmentIndex = -1; segment.segmentedControlStyle = UISegmentedControlStyleBar; segment.tintColor = [UIColor colorWithRed:0.745 green:0.184 blue:0.216 alpha:1]; segment.momentary = YES; segment.alpha = 0.9; [segment insertSegmentWithTitle:@"Ta bort" atIndex:0 animated:NO]; [segment addTarget:self action:@selector(foo:) forControlEvents:UIControlEventValueChanged];

每次我在UISearchField中输入一个字符时,都会运行上面的块。 由于UISearchDisplayDelegate为-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString返回YES -(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString函数。 这导致重新绘制UITableView及其单元格。

现在问题变得更容易处理了。 而我目前正在实施一个可能的解决方案。

Since i updated my iOS software on my iPhone 4, my app that i'm developing has started to lag. This is only happening when i'm giving inputs to a UISearchField.

The "lag" occurs when i've tapped around 30 letters on the iOS keyboard. After that, every consecutive tap lags behind giving the feel that the phone itself can't handle the inputs anymore.

I have a UISearchDisplayController that does Selects to my database whenever i enter three or more letters in my search field.

Here is some code.

The actual search

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { if ([searchText length] >= 3) { if (searchObject != nil) { searchObject = nil; searchObject = [[FritextSok alloc]init]; [searchObject setDelegate:self]; } [searchObject setSearchstring:searchText]; [searchObject search]; } else { // Displays non filtered results. } }

I'm also experiencing this while running the iOS6 simulator.

Also, aside from the iOS keyboard "lag". Every single UISegmentedControl, in different view controllers seems to take FOREVER to draw. This happens after the keyboard mash.

I'm properly reusing cells ( i think ) and have no actual idea what's causing this, since it seems to run perfectly on all iOS versions from 4.3 up to 5.1.

I've tried different ways of allocating the searchObject. Nothing seems to help.

Edit

This is an error message that shows up sporadicly

purgeIdleCellConnections: found one to purge conn = <Memory address>

Edit 2

After some more trial and error with use of the PROFILER-tool. I discovered that the living memory is constantly increasing due to this block.

UISegmentedControl *segment = [[UISegmentedControl alloc] init]; segment.frame = CGRectMake(0, 0, 70, 32); segment.selectedSegmentIndex = -1; segment.segmentedControlStyle = UISegmentedControlStyleBar; segment.tintColor = [UIColor colorWithRed:0.745 green:0.184 blue:0.216 alpha:1]; segment.momentary = YES; segment.alpha = 0.9; [segment insertSegmentWithTitle:@"Ta bort" atIndex:0 animated:NO]; [segment addTarget:self action:@selector(foo:) forControlEvents:UIControlEventValueChanged];

The above block is being run every time i enter a character in the UISearchField. Since the UISearchDisplayDelegate is returning YES for the -(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString function. Which results in a re-drawing of the UITableView and it's cells.

The problem has now become somewhat easier to handle. And i'm currently implementing a possible fix.

最满意答案

解:

移动代码

UISegmentedControl *segment = [[UISegmentedControl alloc] init]; segment.frame = CGRectMake(0, 0, 70, 32); segment.selectedSegmentIndex = -1; segment.segmentedControlStyle = UISegmentedControlStyleBar; segment.tintColor = [UIColor colorWithRed:0.745 green:0.184 blue:0.216 alpha:1]; segment.momentary = YES; segment.alpha = 0.9; [segment insertSegmentWithTitle:@"Ta bort" atIndex:0 animated:NO]; [segment addTarget:self action:@selector(foo:) forControlEvents:UIControlEventValueChanged];

在tableview的实际重新绘制之外。

Solution:

Move code

UISegmentedControl *segment = [[UISegmentedControl alloc] init]; segment.frame = CGRectMake(0, 0, 70, 32); segment.selectedSegmentIndex = -1; segment.segmentedControlStyle = UISegmentedControlStyleBar; segment.tintColor = [UIColor colorWithRed:0.745 green:0.184 blue:0.216 alpha:1]; segment.momentary = YES; segment.alpha = 0.9; [segment insertSegmentWithTitle:@"Ta bort" atIndex:0 animated:NO]; [segment addTarget:self action:@selector(foo:) forControlEvents:UIControlEventValueChanged];

Outside of the actual re-drawing of the tableview.

更多推荐

本文发布于:2023-07-17 07:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141061.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:差异   分配   内存   allocation   Memory

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!