Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableview Delegate methods are not executing
    text
    copied!<p>i tried the following code for searching in epub ,Its not working the reason is 1.The table delegate methode executing at startup so the default value of search results is 0 ,so i give one dummy array with 4 elements in viewdidload method.So now tableview displaying only 4 thode elements in dummy array and when i scroll the tableview it displaying correct search results but still it showing only 4 elemets in that search results because <em>number of rows</em> methode is not execute while scrolling.</p> <p><strong>when i click search button it will call this methode in first class</strong></p> <pre><code>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]; </code></pre> <p><strong>then it calls following methods in searchresult class</strong></p> <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ NSLog(@"%d",[results count]); if([results count]&gt;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]&gt;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)&lt;[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&lt;[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&lt;y2){ return NSOrderedAscending; } else if(y1&gt;y2){ return NSOrderedDescending; } else { if(x1&lt;x2){ return NSOrderedAscending; } else if (x1&gt;x2){ return NSOrderedDescending; } else { return NSOrderedSame; } } }]; [objects release]; for(int i=0; i&lt;[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&lt;[results count];i++) { hit = (SearchResult*)[results objectAtIndex:i]; } [resultsTableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; if((currentChapterIndex+1)&lt;[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); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload