Iphone 目标C:cellForRowAtIndexPath崩溃

Iphone 目标C:cellForRowAtIndexPath崩溃,iphone,objective-c,Iphone,Objective C,我希望用户能够在数据库中搜索记录。提取和返回的结果工作得很好。我很难设置UItableview来显示结果tho。应用程序在cellForRowAtIndexPath上不断崩溃。拜托,在我心脏病发作之前,来人帮忙。多谢各位 @implementation SearchViewController @synthesize mySearchBar; @synthesize textToSearchFor; @synthesize myGlobalSearchObject; @synthesize re

我希望用户能够在数据库中搜索记录。提取和返回的结果工作得很好。我很难设置UItableview来显示结果tho。应用程序在cellForRowAtIndexPath上不断崩溃。拜托,在我心脏病发作之前,来人帮忙。多谢各位

@implementation SearchViewController
@synthesize mySearchBar;
@synthesize textToSearchFor;
@synthesize myGlobalSearchObject;
@synthesize results;
@synthesize tableView;
@synthesize tempString;

#pragma mark -
#pragma mark View lifecycle

- (void)viewDidLoad {
    [super viewDidLoad];
}

#pragma mark -
#pragma mark Table View
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //handle selection; push view
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
/*  if(nullResulSearch == TRUE){
        return 1;
    }else {
        return[results count];
    }   
 */ 
    return[results count];
 }

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;  // Test hack to display multiple rows.
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Search Cell Identifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(cell == nil){
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
    }

    NSLog(@"TEMPSTRING %@", tempString);
    cell.textLabel.text = tempString;

    return cell;    
 }

#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

}

- (void)viewDidUnload {
    self.tableView = nil;
}

- (void)dealloc {
    [results release];
    [mySearchBar release];
    [textToSearchFor release];
    [myGlobalSearchObject release];
    [super dealloc];
}

#pragma mark -
#pragma mark Search Function & Fetch Controller

- (NSManagedObject *)SearchDatabaseForText:(NSString *)passdTextToSearchFor{
    NSManagedObject *searchObj;
    UndergroundBaseballAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];

    NSManagedObjectContext *managedObjectContext = appDelegate.managedObjectContext;
    NSFetchRequest *request = [[NSFetchRequest alloc] init]; 
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name == [c]%@", passdTextToSearchFor]; 
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Entry" inManagedObjectContext:managedObjectContext]; 
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:NO]; 
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];   

    [request setSortDescriptors:sortDescriptors];
    [request setEntity: entity]; 
    [request setPredicate: predicate]; 

    NSError *error;

    results = [managedObjectContext executeFetchRequest:request error:&error];

    if([results count] == 0){
        NSLog(@"No results found");
        searchObj = nil;
        nullResulSearch == TRUE;
    }else{
        if ([[[results objectAtIndex:0] name] caseInsensitiveCompare:passdTextToSearchFor] == 0) {
            NSLog(@"results %@", [[results objectAtIndex:0] name]);
            searchObj = [results objectAtIndex:0];
            nullResulSearch == FALSE;
        }else{
            NSLog(@"No results found");
            searchObj = nil;
            nullResulSearch == TRUE;
        }       
    }

    [tableView reloadData]; 

    [request release];
    [sortDescriptors release];

    return searchObj;
}

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
    textToSearchFor =  mySearchBar.text;
    NSLog(@"textToSearchFor: %@", textToSearchFor);
    myGlobalSearchObject = [self SearchDatabaseForText:textToSearchFor];
    NSLog(@"myGlobalSearchObject: %@", myGlobalSearchObject);
    tempString = [myGlobalSearchObject valueForKey:@"name"];
    NSLog(@"tempString: %@", tempString);   
}
@end



*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UILongPressGestureRecognizer isEqualToString:]: unrecognized selector sent to instance 0x3d46c20'


问题可能与引用计数有关。

-(void)searchBarSearchButtonClicked:(UISearchBar*)searchBar
方法中,尝试以下任一方法

self.tempString = [myGlobalSearchObject valueForKey:@"name"];   
(假设tempString设置为retain)



我还建议检查nil值。i、 e.如果
[myGlobalSearchObject valueForKey:@“name”]==nil怎么办?

问题可能与引用计数有关。

-(void)searchBarSearchButtonClicked:(UISearchBar*)searchBar
方法中,尝试以下任一方法

self.tempString = [myGlobalSearchObject valueForKey:@"name"];   
(假设tempString设置为retain)



我还建议检查nil值。i、 e.如果
[myGlobalSearchObject valueForKey:@“name”]==nil怎么办?

是否记录了tempString的正确值?嗯,tempString的值在searchBarSearchButtonClicked中正确注销,但该日志甚至没有显示在CellForRowAtIndexPath中,它没有说确切的行。上面发布的错误。看起来
cellforrowatinexpath
不是您的问题。这似乎是手势识别的问题。您是否以某种方式自定义UITableView?它是子类的吗?它记录了tempString的正确值吗?嗯,tempString的值在searchBarSearchButtonClicked中正确地注销了,但是日志甚至没有显示在CellForRowatinedExpath中,它没有说确切的行。上面发布的错误。看起来
cellforrowatinexpath
不是您的问题。这似乎是手势识别的问题。您是否以某种方式自定义UITableView?它是子类的吗?