objective c - UITableViewController with UISearchDisplayController not reloading data -


i have viewcontroller class appropriate .xib file. here viewcontroller code:

viewcontroller.h:

#import <uikit/uikit.h> #import <foundation/foundation.h>  @interface viewcontroller : uiviewcontroller {         nsarray *news;     nsmutabledata *data; }  @property (strong, nonatomic) iboutlet uitableview *maintableview; @property (strong, nonatomic) iboutlet uisearchbar *searchbar;  @property (strong, nonatomic) results *result;  @end 

viewcontroller.m:

#import "viewcontroller.h" #import "results.h"  @interface viewcontroller ()  @end  @implementation viewcontroller  @synthesize result, maintableview, searchbar;  -(id) init {     self = [super initwithnibname:@"viewcontroller_iphone" bundle:nil];      if (self)     {         result = [[results alloc] init];         maintableview = [[uitableview alloc] init];         [self.maintableview setdelegate:self];     }      return self; }  - (void)viewdidload {     self.title = @"search";     [[uinavigationbar appearance] settintcolor:[uicolor blackcolor]];      [super viewdidload]; }  - (void)searchbarsearchbuttonclicked:(uisearchbar *)searchbar {     [uiapplication sharedapplication].networkactivityindicatorvisible = yes;     nsstring *query = searchbar.text;     nsurl *url = [nsurl urlwithstring:[nsstring stringwithformat:@"http://samplesite.com/external/metasearchjson.php?query=%@", query]];     nsurlrequest *request = [nsurlrequest requestwithurl:url];     [nsurlconnection connectionwithrequest:request delegate:self]; }  - (void)connection:(nsurlconnection *)connection didreceiveresponse:(nsurlresponse *)response {     data = [[nsmutabledata alloc] init]; }  - (void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)thedata {     [data appenddata:thedata]; }  - (void)connectiondidfinishloading:(nsurlconnection *)connection {     [uiapplication sharedapplication].networkactivityindicatorvisible = no;     nsarray *responsedict = [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingallowfragments error:null];      if ([responsedict iskindofclass:[nsarray class]]) {         news = responsedict;         //[maintableview reloadsections:[nsindexset indexsetwithindex:0] withrowanimation:uitableviewrowanimationfade];         [[self maintableview] reloaddata];         nslog(@"%@", maintableview);     } else {         nslog(@"json error.");     } }  -(void) tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {     uitableviewcell *cell = [tableview cellforrowatindexpath:[nsindexpath indexpathforrow:[indexpath row] insection:0]];     nsstring *url = _getstring([[news objectatindex:[indexpath row]] objectforkey:@"link"]);     [result geturl:url];     [uiapplication sharedapplication].networkactivityindicatorvisible = yes;     [self.navigationcontroller pushviewcontroller:result animated:yes]; }  - (void)connection:(nsurlconnection *)connection didfailwitherror:(nserror *)error {     uialertview *errorview = [[uialertview alloc] initwithtitle:@"error" message:@"the download not complete - please make sure you're connected either 3g or wi-fi." delegate:nil cancelbuttontitle:@"dismiss" otherbuttontitles:nil];     [errorview show];     [uiapplication sharedapplication].networkactivityindicatorvisible = no; }  - (int)numberofsectionsintableview:(uitableview *)tableview {     return 1; }  - (int)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     return [news count]; }  nsstring *_getstring(id obj) {     return [obj iskindofclass:[nsstring class]] ? obj : nil; }  - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:@"maincell"];      if(cell == nil){         cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:@"maincell"];     }      cell.detailtextlabel.text = _getstring([[news objectatindex:indexpath.row] objectforkey:@"metascore"]);     cell.textlabel.text = _getstring([[news objectatindex:indexpath.row] objectforkey:@"title"]);      [cell setaccessorytype:uitableviewcellaccessorydisclosureindicator];      return cell; } 

my connections working, , code puts json data uitableview.

my problem is, table view isn't reloading!

i have tried load without uisearchdisplaycontroller, , works fine. i'm thinking it's sort of override. tableview reloads data, doesn't work. what's weird if type in search display, table view displayed. doing wrong search bar doesn't reload data?

in search display delegate, need implement

- (bool)searchdisplaycontroller:(uisearchdisplaycontroller *)controller shouldreloadtableforsearchstring:(nsstring *)searchstring 

and return yes.


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -