objective c - NSDictionary Search -
objective c - NSDictionary Search -
my nsdictionary retrieving first array in dictionary. have no thought why behaving way.
here search
//loop through datadictionary origin , destination (nsmutabledictionary *floors in [mapdata allfloors]){ //check if found set roomlisttxt , defaultimage dictionary values if ([floors[origin] isequaltostring:origin] && [floors[destination] isequaltostring:destination]) { searchresults.roomlisttxt = floors[destination_rooms]; searchresults.defaultimage = floors[map_image]; [self.navigationcontroller pushviewcontroller:searchresults animated:yes]; //break; } else { uialertview *alert = [[uialertview alloc] initwithtitle:@"oops!!" message:@"working add together more routes." delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil]; [alert show]; break; } } here definition of dictionary
nsdictionary *d1dictionary = @{origin : @"a1", destination : @"d1", origin_rooms : @"a101, a102, a113", destination_rooms : @"d100, d100c, d101, d102, d103, d105, d107, d111, d113", map_image : [uiimage imagenamed:@"a1-d1.png"]}; [floorsinformation addobject:d1dictionary]; nsdictionary *d2dictionary = @{origin : @"a1", destination : @"m1", origin_rooms : @"a101, a102, a113", destination_rooms : @"m104, m105, m106, m107", map_image : [uiimage imagenamed:@"a1-m1.png"]}; [floorsinformation addobject:d2dictionary]; the input parameters 'origin' , 'destination' equal "floors[origin]" , "floors[destination]" respectively.
your else block within loop. showing first result because on sec loop, status evaluates no, triggering alert , break command.
you can verify setting breakpoint , stepping through code. can resolve issue checking appropriate info before or after iteration loop, appropriate app's feature.
for example:
for (nsmutabledictionary *floors in [mapdata allfloors]){ //check if found set roomlisttxt , defaultimage dictionary values if ([floors[origin] isequaltostring:origin] && [floors[destination] isequaltostring:destination]) { searchresults.roomlisttxt = floors[destination_rooms]; searchresults.defaultimage = floors[map_image]; [self.navigationcontroller pushviewcontroller:searchresults animated:yes]; return; } } // due 'return' statement, code won't called if match made uialertview *alert = [[uialertview alloc] initwithtitle:@"oops!!" message:@"working add together more routes." delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil]; [alert show]; objective-c nsarray nsdictionary
Comments
Post a Comment