Ios UITableview委托方法未执行

Ios UITableview委托方法未执行,ios,objective-c,uitableview,search,Ios,Objective C,Uitableview,Search,我尝试了以下代码在epub中搜索,它不起作用的原因是 1.启动时执行的表委托方法,因此搜索结果的默认值为0,因此,我在viewdidload方法中给出了一个包含4个元素的虚拟数组。因此,现在tableview在虚拟数组中仅显示4个thode元素,当我滚动tableview时,它显示正确的搜索结果,但仍然在该搜索结果中仅显示4个元素,因为滚动时不会执行行数方法 当我单击搜索按钮时,它将在头等舱中调用此方法 SearchResultsViewController *searchRes=[[Searc

我尝试了以下代码在epub中搜索,它不起作用的原因是 1.启动时执行的表委托方法,因此搜索结果的默认值为0,因此,我在viewdidload方法中给出了一个包含4个元素的虚拟数组。因此,现在tableview在虚拟数组中仅显示4个thode元素,当我滚动tableview时,它显示正确的搜索结果,但仍然在该搜索结果中仅显示4个元素,因为滚动时不会执行行数方法

当我单击搜索按钮时,它将在头等舱中调用此方法

SearchResultsViewController *searchRes=[[SearchResultsViewController alloc]initWithNibName:@"SearchResultsViewController" bundle:nil];
NSString *searchQuery=[search text];
sharedManager=[Mymanager sharedManager];
sharedManager.searchQuery=searchQuery;
// UITextField *textField = [NSString stringWithFormat:@"%@",searchQuery];
// [textField setFont:[UIFont fontWithName:@"BL-Ruthika-Bold" size:15]];
[searchRes searchString:searchQuery];

[self.navigationController pushViewController:searchRes animated:YES];
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    NSLog(@"%d",[results count]);
    if([results count]>0)
    {
        return [results count];
    }
    else
    {
        return [test count];
    }
}

//executes only at the startup time ,so the value of results always become zero

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }

    if([results count]>0) {
       // cell.textLabel.adjustsFontSizeToFitWidth = YES;

        hit = (SearchResult*)[results objectAtIndex:[indexPath row]];
        cell.textLabel.text = [NSString stringWithFormat:@"...%@...", hit.neighboringText];
        cell.detailTextLabel.text = [NSString stringWithFormat:@"Chapter %d - page %d", hit.chapterIndex, hit.pageIndex+1];
        cell.textLabel.font = [UIFont fontWithName:@"Trebuchet MS" size:13];
        cell.textLabel.textColor = [UIColor colorWithRed:25/255.0 green:90/255.0 blue:100/255.0 alpha:1];

        cell.detailTextLabel.textColor=[UIColor colorWithRed:25/255.0 green:90/255.0 blue:100/255.0 alpha:1];
        cell.detailTextLabel.font= [UIFont fontWithName:@"Trebuchet MS" size:10];

        return cell;
    }
    else
    {
        cell.textLabel.text=[test objectAtIndex:indexPath.row];
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    sharedManager=[Mymanager sharedManager];
    hit = (SearchResult*)[results objectAtIndex:[indexPath row]];
    sharedManager.searchFlag=YES;
    sharedManager.hitPageNumber=hit.pageIndex;
    sharedManager.hitChapter=hit.chapterIndex;
    sharedManager.hit=hit;
    //    [fvc loadSpine:hit.chapterIndex atPageIndex:hit.pageIndex highlightSearchResult:hit];
    [self.navigationController popViewControllerAnimated:YES];

}

- (void) searchString:(NSString*)query{
           currentQuery=sharedManager.searchQuery;
        [self searchString:currentQuery inChapterAtIndex:0];
        [[self resultsTableView]reloadData];
    }

- (void) searchString:(NSString *)query inChapterAtIndex:(int)index{

    currentChapterIndex = index;
    sharedManager=[Mymanager sharedManager];
    Chapter* chapter = [sharedManager.spineArray objectAtIndex:index];
       NSRange range = NSMakeRange(0, chapter.text.length);

     NSLog(@"%@",sharedManager.searchQuery);
    range = [chapter.text rangeOfString:sharedManager.searchQuery options:NSCaseInsensitiveSearch range:range locale:nil];
    int hitCount=0;
    while (range.location != NSNotFound) {
        range = NSMakeRange(range.location+range.length, chapter.text.length-(range.location+range.length));
        range = [chapter.text rangeOfString:sharedManager.searchQuery  options:NSCaseInsensitiveSearch range:range locale:nil];
        hitCount++;
    }

    if(hitCount!=0){
        UIWebView* webView = [[UIWebView alloc] initWithFrame:chapter.windowSize];
        [webView setDelegate:self];
        NSURLRequest* urlRequest = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:chapter.spinePath]];
        [webView loadRequest:urlRequest];
    } else {
        if((currentChapterIndex+1)<[sharedManager.spineArray count]){
            [self searchString:sharedManager.searchQuery inChapterAtIndex:(currentChapterIndex+1)];
        } else {
            fvc.searching = NO;
        }
    }
}    

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    // NSLog(@"%@", error);
    [webView release];
}

- (void) webViewDidFinishLoad:(UIWebView*)webView{

    sharedManager=[Mymanager sharedManager];

    NSString *varMySheet = @"var mySheet = document.styleSheets[0];";

    NSString *addCSSRule =  @"function addCSSRule(selector, newRule) {"
    "if (mySheet.addRule) {"
    "mySheet.addRule(selector, newRule);"                               // For Internet Explorer
    "} else {"
    "ruleIndex = mySheet.cssRules.length;"
    "mySheet.insertRule(selector + '{' + newRule + ';}', ruleIndex);"   // For Firefox, Chrome, etc.
    "}"
    "}";

    NSString *insertRule1 = [NSString stringWithFormat:@"addCSSRule('html', 'padding: 0px; height: %fpx; -webkit-column-gap: 0px; -webkit-column-width: %fpx;')", webView.frame.size.height, webView.frame.size.width];
    NSString *insertRule2 = [NSString stringWithFormat:@"addCSSRule('p', 'text-align: justify;')"];

    NSString *setTextSizeRule = [NSString stringWithFormat:@"addCSSRule('body', '-webkit-text-size-adjust: %d%%;')",[[sharedManager.spineArray objectAtIndex:currentChapterIndex] fontPercentSize]];

    [webView stringByEvaluatingJavaScriptFromString:varMySheet];

    [webView stringByEvaluatingJavaScriptFromString:addCSSRule];

    [webView stringByEvaluatingJavaScriptFromString:insertRule1];

    [webView stringByEvaluatingJavaScriptFromString:insertRule2];

    [webView stringByEvaluatingJavaScriptFromString:setTextSizeRule];
    [webView highlightAllOccurencesOfString:sharedManager.searchQuery];

    NSString* foundHits = [webView stringByEvaluatingJavaScriptFromString:@"results"];

     NSLog(@"%@", foundHits);

    NSMutableArray* objects = [[NSMutableArray alloc] init];

    NSArray* stringObjects = [foundHits componentsSeparatedByString:@";"];
    for(int i=0; i<[stringObjects count]; i++){
        NSArray* strObj = [[stringObjects objectAtIndex:i] componentsSeparatedByString:@","];
        if([strObj count]==3){
            [objects addObject:strObj];
        }
    }

    NSArray* orderedRes = [objects sortedArrayUsingComparator:^(id obj1, id obj2){
        int x1 = [[obj1 objectAtIndex:0] intValue];
        int x2 = [[obj2 objectAtIndex:0] intValue];
        int y1 = [[obj1 objectAtIndex:1] intValue];
        int y2 = [[obj2 objectAtIndex:1] intValue];
        if(y1<y2){
            return NSOrderedAscending;
        } else if(y1>y2){
            return NSOrderedDescending;
        } else {
            if(x1<x2){
                return NSOrderedAscending;
            } else if (x1>x2){
                return NSOrderedDescending;
            } else {
                return NSOrderedSame;
            }
        }
    }];

    [objects release];

    for(int i=0; i<[orderedRes count]; i++){
        NSArray* currObj = [orderedRes objectAtIndex:i];

        SearchResult* searchRes = [[SearchResult alloc] initWithChapterIndex:currentChapterIndex pageIndex:([[currObj objectAtIndex:1] intValue]/webView.bounds.size.height) hitIndex:0 neighboringText:[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"unescape('%@')", [currObj objectAtIndex:2]]] originatingQuery:sharedManager.searchQuery];
        [results addObject:searchRes];

        [searchRes release];
    }

         [[self resultsTableView]reloadData];
    //Print results

    for(int i=0;i<[results count];i++)
    {
        hit = (SearchResult*)[results objectAtIndex:i];
    }

    [resultsTableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
    if((currentChapterIndex+1)<[sharedManager.spineArray count]){
        [self searchString:sharedManager.searchQuery inChapterAtIndex:(currentChapterIndex+1)];
    } else {
        fvc.searching= NO;
    }

    [[self resultsTableView]reloadData];


}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    resultsTableView=[[UITableView alloc]init];
    [resultsTableView setDelegate:self];
    [resultsTableView setDataSource:self];

    sharedManager=[Mymanager sharedManager];
    // Do any additional setup after loading the view from its nib.
    results = [[NSMutableArray alloc] init];
    test=[[NSArray alloc]initWithObjects:@"one",@"one",@"one",@"one",nil];
    self.navigationItem.title=@"Search ";
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
                                   initWithTitle:@"Back"
                                   style:UIBarButtonItemStylePlain
                                   target:nil
                                   action:nil];
    self.navigationItem.backBarButtonItem=backButton;

    [[UINavigationBar appearance] setTitleTextAttributes: @{
                                UITextAttributeTextColor: [UIColor whiteColor],
                          UITextAttributeTextShadowColor: [UIColor lightGrayColor],
                         UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],
                                     UITextAttributeFont: [UIFont fontWithName:@"Trebuchet MS" size:15.0f]
     }];

    [self searchString:sharedManager.searchQuery];
    noMatchingSearch=[[NSArray alloc]initWithObjects:@"No Element Found", nil];

    tableOfContents=[[NSMutableArray alloc]init];
    for (id img in search.subviews)
    {
        if ([img isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
        {
            [img removeFromSuperview];
        }
    }

    tableOfContents=[sharedManager.List copy];

}

- (void)viewDidUnload
{
    search = nil;
    [super viewDidUnload];
    resultsTableView.delegate=self;
    resultsTableView.dataSource=self;
    // Release any retained subviews of the main view.
    self.resultsTableView = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
然后在searchresult类中调用以下方法

SearchResultsViewController *searchRes=[[SearchResultsViewController alloc]initWithNibName:@"SearchResultsViewController" bundle:nil];
NSString *searchQuery=[search text];
sharedManager=[Mymanager sharedManager];
sharedManager.searchQuery=searchQuery;
// UITextField *textField = [NSString stringWithFormat:@"%@",searchQuery];
// [textField setFont:[UIFont fontWithName:@"BL-Ruthika-Bold" size:15]];
[searchRes searchString:searchQuery];

[self.navigationController pushViewController:searchRes animated:YES];
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    NSLog(@"%d",[results count]);
    if([results count]>0)
    {
        return [results count];
    }
    else
    {
        return [test count];
    }
}

//executes only at the startup time ,so the value of results always become zero

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }

    if([results count]>0) {
       // cell.textLabel.adjustsFontSizeToFitWidth = YES;

        hit = (SearchResult*)[results objectAtIndex:[indexPath row]];
        cell.textLabel.text = [NSString stringWithFormat:@"...%@...", hit.neighboringText];
        cell.detailTextLabel.text = [NSString stringWithFormat:@"Chapter %d - page %d", hit.chapterIndex, hit.pageIndex+1];
        cell.textLabel.font = [UIFont fontWithName:@"Trebuchet MS" size:13];
        cell.textLabel.textColor = [UIColor colorWithRed:25/255.0 green:90/255.0 blue:100/255.0 alpha:1];

        cell.detailTextLabel.textColor=[UIColor colorWithRed:25/255.0 green:90/255.0 blue:100/255.0 alpha:1];
        cell.detailTextLabel.font= [UIFont fontWithName:@"Trebuchet MS" size:10];

        return cell;
    }
    else
    {
        cell.textLabel.text=[test objectAtIndex:indexPath.row];
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    sharedManager=[Mymanager sharedManager];
    hit = (SearchResult*)[results objectAtIndex:[indexPath row]];
    sharedManager.searchFlag=YES;
    sharedManager.hitPageNumber=hit.pageIndex;
    sharedManager.hitChapter=hit.chapterIndex;
    sharedManager.hit=hit;
    //    [fvc loadSpine:hit.chapterIndex atPageIndex:hit.pageIndex highlightSearchResult:hit];
    [self.navigationController popViewControllerAnimated:YES];

}

- (void) searchString:(NSString*)query{
           currentQuery=sharedManager.searchQuery;
        [self searchString:currentQuery inChapterAtIndex:0];
        [[self resultsTableView]reloadData];
    }

- (void) searchString:(NSString *)query inChapterAtIndex:(int)index{

    currentChapterIndex = index;
    sharedManager=[Mymanager sharedManager];
    Chapter* chapter = [sharedManager.spineArray objectAtIndex:index];
       NSRange range = NSMakeRange(0, chapter.text.length);

     NSLog(@"%@",sharedManager.searchQuery);
    range = [chapter.text rangeOfString:sharedManager.searchQuery options:NSCaseInsensitiveSearch range:range locale:nil];
    int hitCount=0;
    while (range.location != NSNotFound) {
        range = NSMakeRange(range.location+range.length, chapter.text.length-(range.location+range.length));
        range = [chapter.text rangeOfString:sharedManager.searchQuery  options:NSCaseInsensitiveSearch range:range locale:nil];
        hitCount++;
    }

    if(hitCount!=0){
        UIWebView* webView = [[UIWebView alloc] initWithFrame:chapter.windowSize];
        [webView setDelegate:self];
        NSURLRequest* urlRequest = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:chapter.spinePath]];
        [webView loadRequest:urlRequest];
    } else {
        if((currentChapterIndex+1)<[sharedManager.spineArray count]){
            [self searchString:sharedManager.searchQuery inChapterAtIndex:(currentChapterIndex+1)];
        } else {
            fvc.searching = NO;
        }
    }
}    

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    // NSLog(@"%@", error);
    [webView release];
}

- (void) webViewDidFinishLoad:(UIWebView*)webView{

    sharedManager=[Mymanager sharedManager];

    NSString *varMySheet = @"var mySheet = document.styleSheets[0];";

    NSString *addCSSRule =  @"function addCSSRule(selector, newRule) {"
    "if (mySheet.addRule) {"
    "mySheet.addRule(selector, newRule);"                               // For Internet Explorer
    "} else {"
    "ruleIndex = mySheet.cssRules.length;"
    "mySheet.insertRule(selector + '{' + newRule + ';}', ruleIndex);"   // For Firefox, Chrome, etc.
    "}"
    "}";

    NSString *insertRule1 = [NSString stringWithFormat:@"addCSSRule('html', 'padding: 0px; height: %fpx; -webkit-column-gap: 0px; -webkit-column-width: %fpx;')", webView.frame.size.height, webView.frame.size.width];
    NSString *insertRule2 = [NSString stringWithFormat:@"addCSSRule('p', 'text-align: justify;')"];

    NSString *setTextSizeRule = [NSString stringWithFormat:@"addCSSRule('body', '-webkit-text-size-adjust: %d%%;')",[[sharedManager.spineArray objectAtIndex:currentChapterIndex] fontPercentSize]];

    [webView stringByEvaluatingJavaScriptFromString:varMySheet];

    [webView stringByEvaluatingJavaScriptFromString:addCSSRule];

    [webView stringByEvaluatingJavaScriptFromString:insertRule1];

    [webView stringByEvaluatingJavaScriptFromString:insertRule2];

    [webView stringByEvaluatingJavaScriptFromString:setTextSizeRule];
    [webView highlightAllOccurencesOfString:sharedManager.searchQuery];

    NSString* foundHits = [webView stringByEvaluatingJavaScriptFromString:@"results"];

     NSLog(@"%@", foundHits);

    NSMutableArray* objects = [[NSMutableArray alloc] init];

    NSArray* stringObjects = [foundHits componentsSeparatedByString:@";"];
    for(int i=0; i<[stringObjects count]; i++){
        NSArray* strObj = [[stringObjects objectAtIndex:i] componentsSeparatedByString:@","];
        if([strObj count]==3){
            [objects addObject:strObj];
        }
    }

    NSArray* orderedRes = [objects sortedArrayUsingComparator:^(id obj1, id obj2){
        int x1 = [[obj1 objectAtIndex:0] intValue];
        int x2 = [[obj2 objectAtIndex:0] intValue];
        int y1 = [[obj1 objectAtIndex:1] intValue];
        int y2 = [[obj2 objectAtIndex:1] intValue];
        if(y1<y2){
            return NSOrderedAscending;
        } else if(y1>y2){
            return NSOrderedDescending;
        } else {
            if(x1<x2){
                return NSOrderedAscending;
            } else if (x1>x2){
                return NSOrderedDescending;
            } else {
                return NSOrderedSame;
            }
        }
    }];

    [objects release];

    for(int i=0; i<[orderedRes count]; i++){
        NSArray* currObj = [orderedRes objectAtIndex:i];

        SearchResult* searchRes = [[SearchResult alloc] initWithChapterIndex:currentChapterIndex pageIndex:([[currObj objectAtIndex:1] intValue]/webView.bounds.size.height) hitIndex:0 neighboringText:[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"unescape('%@')", [currObj objectAtIndex:2]]] originatingQuery:sharedManager.searchQuery];
        [results addObject:searchRes];

        [searchRes release];
    }

         [[self resultsTableView]reloadData];
    //Print results

    for(int i=0;i<[results count];i++)
    {
        hit = (SearchResult*)[results objectAtIndex:i];
    }

    [resultsTableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
    if((currentChapterIndex+1)<[sharedManager.spineArray count]){
        [self searchString:sharedManager.searchQuery inChapterAtIndex:(currentChapterIndex+1)];
    } else {
        fvc.searching= NO;
    }

    [[self resultsTableView]reloadData];


}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    resultsTableView=[[UITableView alloc]init];
    [resultsTableView setDelegate:self];
    [resultsTableView setDataSource:self];

    sharedManager=[Mymanager sharedManager];
    // Do any additional setup after loading the view from its nib.
    results = [[NSMutableArray alloc] init];
    test=[[NSArray alloc]initWithObjects:@"one",@"one",@"one",@"one",nil];
    self.navigationItem.title=@"Search ";
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
                                   initWithTitle:@"Back"
                                   style:UIBarButtonItemStylePlain
                                   target:nil
                                   action:nil];
    self.navigationItem.backBarButtonItem=backButton;

    [[UINavigationBar appearance] setTitleTextAttributes: @{
                                UITextAttributeTextColor: [UIColor whiteColor],
                          UITextAttributeTextShadowColor: [UIColor lightGrayColor],
                         UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],
                                     UITextAttributeFont: [UIFont fontWithName:@"Trebuchet MS" size:15.0f]
     }];

    [self searchString:sharedManager.searchQuery];
    noMatchingSearch=[[NSArray alloc]initWithObjects:@"No Element Found", nil];

    tableOfContents=[[NSMutableArray alloc]init];
    for (id img in search.subviews)
    {
        if ([img isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
        {
            [img removeFromSuperview];
        }
    }

    tableOfContents=[sharedManager.List copy];

}

- (void)viewDidUnload
{
    search = nil;
    [super viewDidUnload];
    resultsTableView.delegate=self;
    resultsTableView.dataSource=self;
    // Release any retained subviews of the main view.
    self.resultsTableView = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节{
NSLog(@“%d”,[结果计数]);
如果([结果计数]>0)
{
返回[结果计数];
}
其他的
{
返回[测试计数];
}
}
//仅在启动时执行,因此结果值始终为零
-(UITableViewCell*)tableView:(UITableView*)tableView1 cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*CellIdentifier=@“Cell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle重用标识符:CellIdentifier]自动释放];
}
如果([结果计数]>0){
//cell.textlab.adjustsFontSizeToFitWidth=是;
hit=(SearchResult*)[results objectAtIndex:[indexPath行]];
cell.textLabel.text=[NSString stringWithFormat:@“…%@…”,点击.NeightringText];
cell.detailTextLabel.text=[NSString stringWithFormat:@“第%d章-第%d页”,hit.chapterIndex,hit.pageIndex+1];
cell.textlab.font=[UIFont fontWithName:@“投石机MS”大小:13];
cell.textlab.textColor=[UIColor colorWithRed:25/255.0绿色:90/255.0蓝色:100/255.0 alpha:1];
cell.detailtextlab.textColor=[uicolorWithred:25/255.0绿色:90/255.0蓝色:100/255.0 alpha:1];
cell.detailTextLabel.font=[UIFont fontWithName:@“投石机MS”大小:10];
返回单元;
}
其他的
{
cell.textLabel.text=[TestObjectAtIndex:indexath.row];
返回单元;
}
}
-(void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath{
sharedManager=[Mymanager sharedManager];
hit=(SearchResult*)[results objectAtIndex:[indexPath行]];
sharedManager.searchFlag=是;
sharedManager.hitPageNumber=hit.pageIndex;
sharedManager.hitChapter=hit.chapterIndex;
sharedManager.hit=hit;
//[fvc loadSpine:hit.chapterIndex atPageIndex:hit.pageIndex highlightSearchResult:hit];
[self.navigationController PopViewControllerInitiated:是];
}
-(void)searchString:(NSString*)查询{
currentQuery=sharedManager.searchQuery;
[自搜索字符串:currentQuery InCapteraIndex:0];
[[self resultsTableView]重新加载数据];
}
-(void)searchString:(NSString*)查询InCapteratIndex:(int)索引{
currentChapterIndex=索引;
sharedManager=[Mymanager sharedManager];
章*章=[sharedManager.spineArray对象索引:索引];
NSRange range=NSMakeRange(0,chapter.text.length);
NSLog(@“%@”,sharedManager.searchQuery);
range=[chapter.text rangeOfString:sharedManager.searchQuery选项:NSCaseInsensitiveSearch范围:范围区域设置:nil];
整数命中率=0;
while(range.location!=NSNotFound){
range=NSMakeRange(range.location+range.length,chapter.text.length-(range.location+range.length));
range=[chapter.text rangeOfString:sharedManager.searchQuery选项:NSCaseInsensitiveSearch范围:范围区域设置:nil];
命中率++;
}
如果(命中率!=0){
UIWebView*webView=[[UIWebView alloc]initWithFrame:chapter.windowSize];
[webView setDelegate:self];
NSURLRequest*urlRequest=[nsurlRequestRequestWithURL:[NSURL fileURLWithPath:chapter.spinePath]];
[webView loadRequest:urlRequest];
}否则{

如果((currentChapterIndex+1)当您收到搜索结果呼叫时

[self.tableView reloadData];
告诉表视图更新自身。我可以看到您在上面的大量代码中已经尝试过多次。您只需要在搜索结果就绪时调用它一次。此外,请确保调用表视图时对它的引用有效

此外,如果您在XIB文件中创建表视图,那么在
viewDidLoad
中创建的第二个表视图(添加为子视图)并没有显示出来,这会让您感到困惑,并且您试图重新加载错误的表视图

    resultsTableView=[[UITableView alloc]init];

如果仍然存在问题,请显示类属性并删除与表视图无关的所有代码。

当您收到搜索结果调用时

[self.tableView reloadData];
    resultsTableView=[[UITableView alloc]init];
告诉表视图更新自身。我可以看到您在上面的大量代码中已经尝试过多次。您只需要在搜索结果就绪时调用它一次。此外,请确保调用表视图时对它的引用有效

此外,如果您在XIB文件中创建表视图,那么在
viewDidLoad
中创建的第二个表视图(添加为子视图)并没有显示出来,这会让您感到困惑,并且您试图重新加载错误的表视图

    resultsTableView=[[UITableView alloc]init];
如果仍然存在问题,请显示类属性并删除与表视图无关的所有代码

    resultsTableView=[[UITableView alloc]init];
尝试使用带有属性的resultsTableView,并将其设置为(非原子,强)


尝试使用带有属性的resultsTableView,并将其设置为(非原子,强).

u可以看到我已经做了,但它没有调用委托我不知道y?在那个webview中,我得到了结果数组值,但它不工作。u可以看到我已经做了,但它没有调用委托我不知道y?在那个webview中,我得到了结果数组值,但它不工作