gpt4 book ai didi

iphone - 当函数被延迟调用时,我得到了错误的访问异常

转载 作者:行者123 更新时间:2023-11-28 22:42:55 26 4
gpt4 key购买 nike

我想搜索数组中的数据并刷新 TableView ,但是当我调用延迟函数时,我得到了 BAD ACCESS 异常并且无法工作。但我在延迟一段时间后想要这个功能这是我的代码这是我的完整类(class)

 #import "ViewController.h"
#import "DBHandler.h"
#import "placeDC.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];


DBHandler *db = [[DBHandler alloc]init];
dataArray=[db autoComplete];
isSearching=0;

myTableView.hidden=YES;
// Do any additional setup after loading the view, typically from a nib.

dispalyPlaces=[[NSMutableArray alloc] initWithArray:dataArray];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(isSearching)
{
return [dispalyPlaces count];
}
else
return [dataArray count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 44;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

/* FOR SIMPLE CELL */
static NSString *MyIdentifier = @"MyCell";

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
placeDC *palcedc;

// NSLog(@"%d",isSearching);
if(isSearching)
{
palcedc = [dispalyPlaces objectAtIndex:[indexPath row]];
}
else
{
palcedc = [dataArray objectAtIndex:[indexPath row]];
}
cell.textLabel.text = palcedc.placeNmae;

return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{




}

-(void)delayCall{
for (placeDC *placedc in dataArray) {
NSRange r ;

r = [placedc.placeNmae rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (r.location!=NSNotFound) {
[dispalyPlaces addObject:placedc];
}
}
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
if ([string length]==0) {

[dispalyPlaces removeAllObjects];
[dispalyPlaces addObjectsFromArray:dataArray];
isSearching = 0;

myTableView.hidden=YES;
}
else{
isSearching=1;
searchText=textField.text;
[dispalyPlaces removeAllObjects];
myTableView.hidden=NO;

[self performSelector:@selector(delayCall) withObject:nil afterDelay:0.1];

// [self delayCall];

// for (placeDC *placedc in dataArray) {
// NSRange r ;
// NSLog(@"%@",placedc.placeNmae);
//
//
// r = [placedc.placeNmae rangeOfString:textField.text options:NSCaseInsensitiveSearch];
//
//
// if (r.location!=NSNotFound) {
// [dispalyPlaces addObject:placedc];
// }
// }
[myTableView reloadData];

}
NSLog(@"%d",[dispalyPlaces count]);
return YES;

}


//- (void)searchBar:(UITextField *)searchBar textDidChange:(NSString *)searchText{
//
// if ([txtSearch.text length]==0) {
// myTableView.hidden=YES;
// }
//
// else{
// myTableView.hidden=NO;
// [dispalyPlaces removeAllObjects];
// for (placeDC *palce in dataArray) {
// NSRange r ;
//
// r = [palce.placeNmae rangeOfString:searchText options:NSCaseInsensitiveSearch];
// }
//
// }
//
//}
//
//- (void)dealloc {
// [myTableView release];
// [txtSearch release];
// [super dealloc];
//}
@end

最佳答案

请转到产品>编辑架构>对角线>启用僵尸对象

运行项目并尝试立即崩溃。它将为您提供有关哪个对象导致崩溃的信息。查看该对象,您的错误将得到解决

关于iphone - 当函数被延迟调用时,我得到了错误的访问异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13990427/

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