i have uitableview
filled songs taken server. loading songs 10 10 when scroll tableview. wanted add search functionality this. used uitextfield
. how implemented searching.
in viewdidload
[[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(textfieldtextdidchangeoneci:) name:uitextfieldtextdidchangenotification object:srchtextbox]; -(void)textfieldtextdidchangeoneci:(nsnotification *)notification { [nsobject cancelpreviousperformrequestswithtarget:self selector:@selector(getartistsongs) object:nil]; [nsobject cancelpreviousperformrequestswithtarget:self selector:@selector(searchlocalsong) object:nil]; currentsrchstr = srchtextbox.text; songstable.hidden=yes; loading=yes; songarray=[[nsmutablearray alloc]init]; datacamenull=no; startrec=0; if (dm.isfromlocal) { [self performselectorinbackground:@selector(searchlocalsong) withobject:nil]; } else { [self performselectorinbackground:@selector(getartistsongs) withobject:nil]; } }
my getartistsongs method
-(void)getartistsongs { nsmutablearray *newsongarray; if(dm.isfromlocal) { newsongarray=[dbaccess getlocalplaylistsongs:lblartistname.text]; [songarray removeallobjects]; } else { newsongarray=[ws getplaylistsongsbypage:selectedplaylistid :currentsrchstr :0 :0 :0 :0 :startrec :reccount]; } if (newsongarray!=nil) { [songarray addobjectsfromarray:newsongarray]; } else { songcamenull=yes; } [self performselectoronmainthread:@selector(songsloaded) withobject:nil waituntildone:no]; }
then
-(void)songsloaded{ loading=no; [mainactivityindicator stopanimating]; [songstable reloaddata]; songstable.hidden=no; songstable.tablefooterview = [[uiview alloc] initwithframe:cgrectzero]; }
my problem results getting duplicate.songs searching correctly. if there song called 'song abc' duplicates several times.when check songarray
in log cat, contains same song multiple times. should reason this. please me. thanks
possibly problem might in else
case, not flush songarray
contents:
-(void)getartistsongs { nsmutablearray *newsongarray; if(dm.isfromlocal) { newsongarray=[dbaccess getlocalplaylistsongs:lblartistname.text]; [songarray removeallobjects]; } else { newsongarray=[ws getplaylistsongsbypage:selectedplaylistid :currentsrchstr :0 :0 :0 :0 :startrec :reccount]; [songarray removeallobjects]; // <---------- here }
Comments
Post a Comment