我有一个包含几个NSMutableDictionary对象的数组. 每次填写文本字段并按下提交按钮: //The stringsNSString *dateString = @"Date";NSString *timeString = @"Time";NSString *typeString = @"Type";- (IBAction)addData:(id)s
每次填写文本字段并按下提交按钮:
//The strings NSString *dateString = @"Date"; NSString *timeString = @"Time"; NSString *typeString = @"Type"; - (IBAction)addData:(id)sender { [_myDictionary setObject:_dateLabel.text forKey:dateString]; [_myDictionary setObject:_nNumber.text forKey:timeString]; [_myDictionary setObject:_type.text forKey:typeString]; [_myArray addObject:_myDictionary]; [self display] }
然后我试图在UItextView中显示结果(在这个例子中是日期),但我不知道如何.
-(void)displayData{ for (int i = 0; i<_myArray.count; i++) { [_myArray objectAtIndex:i]; outputString = [outputString stringByAppendingFormat:@"%@\n",[_myDictionary objectForKey:@"Date"]]; } _myTextView.text = [NSString stringWithFormat:@"%@",outputString]; }
这最终显示数组中最后一个Dictionary的日期.我甚至无法弄清楚如何从特定的字典中记录日期.
说[_myArray objectAtIndex:3] [_myDictionary objectForKey:@“Date”].我如何记录第三个索引的日期?
希望这是有道理的
EDIT SOLUTION for (int i = 0; i<_myArray.count; i++) { outputString = [outputString stringByAppendingFormat:@"%@ %@\n",[[_myArray objectAtIndex:i]objectForKey:@"Date"], [[_myArray objectAtIndex:i]objectForKey:@"Time"]]; } _myTextView.text = [NSString stringWithFormat:@"%@",outputString]; }
感谢所有的快速帮助!!
for(int i =0 ;i <[array count];i++) { NSLog(@"%@",[[array objectAtIndex:i]allKeys]); }
此方法将打印所有键