我想要做一個if/else語句,它檢查數組是否爲空。看來第一個條件被評估並且沒有被滿足,所以它移動到else並執行。這是屏幕(IOS)的輸出:如果條件滿足,但if語句的內容似乎沒有執行
,你看到的是那裏,因爲else語句被執行的名稱。但是,有3個其他用戶名分數爲0,沒有得到顯示。下面是相關條件:
NSArray *keyArray = [yy allKeys];
for(NSString *keyd in keyArray) {
NSLog(@"yy objectforkey *********: %@", [[yy objectForKey:keyd] debugDescription]);
if(![yy objectForKey:keyd]){
NSMutableDictionary* entry = [NSMutableDictionary new];
NSLog(@"inside yy object for key count 0 *****####***##*#*#*#");
[tableData addObject:keyd];
[matchesForUser addObject:@"0"];
entry[@"username"] = keyd;
entry[@"matches"] = @"0";
[entries addObject:entry];
}
else {
NSMutableArray *locs = [[NSMutableArray alloc] initWithArray:[yy objectForKey:keyd]];
//NSString *outerouter;
//NSNumber *outeroutermatches = [NSNumber numberWithInt:0];
for(NSDictionary *outterar in locs) {
NSMutableDictionary* entry = [NSMutableDictionary new];
NSLog(@"%@ outtererjar descriptiong ##(#(#(#(#(#(#(#(#(#((#", [outterar description]);
entry[@"username"] = keyd;
entry[@"matches"] = [outterar valueForKey:@"groupmatches"];
if([entries count] > 0) {
for(int counter = 0; counter < [entries count]; counter++) {
if([[[entries objectAtIndex:counter] valueForKey:@"matches"] intValue] < [[entry valueForKey:@"matches"] intValue]) {
NSLog(@"GETTING IN IFFFFFF ABOOOVVEEEEE ******8888888*********");
//NSMutableDictionary *stud = [[NSMutableDictionary alloc] initWithObjectsAndKeys:keyd, @"username", nil];
[matchesForUser addObject:[outterar objectForKey:@"groupmatches"]];
[tableData addObject:keyd];
NSLog(@"%@ WHAT IS ENTRIES>>>!!!!??!?!?!", [[entries objectAtIndex:counter] valueForKey:@"username"]);
if([keyd isEqualToString:[[entries objectAtIndex:counter] valueForKey:@"username"]]) {
NSLog(@"GETTING IN IFFFFFF ******8888888*********");
[entries removeObjectAtIndex:counter];
[entries insertObject:entry atIndex:counter];
}
else {
[entries addObject:entry];
}
}
else {
[entries addObject:entry];
}
}
}
else {
[matchesForUser addObject:[outterar objectForKey:@"groupmatches"]];
[tableData addObject:keyd];
[entries addObject:entry];
}
}
}
}
_tableViewScore
和tableData
是被用來填充兩個陣列的UIScrollView
(多個)。 if語句中的代碼應該在每次找到空對象時執行(它們是數組)。其他的運行,這就是爲什麼你看到用戶名與分數,但它似乎是如果沒有得到執行時,數組爲空。
當我輸出我檢查的對象,一個空的物體看起來是這樣的:
yy objectforkey *********: <__NSArrayM 0x170454cd0>(
)
我只需要能夠識別時的對象之一就是這樣。謝謝!
我可以爲-1解釋? – ewizard