Я делаю небольшую концепцию на NSMutableDictionary.У меня есть четыре ключа (имя, возраст, номер телефона, пол) для 10 сотрудников.
Как я могу присвоить эти значения массиву?
По отдельности я пропустил 4 разныхзначения для словаря, но четвертое значение прибывает многократно.это код, который я написал - (void) viewDidLoad {
NSLog(@"in mytableviews viewdidload");
EmpArray=[[NSMutableArray alloc]init];
//namesArray=[[NSMutableArray alloc]initWithObjects:@"jam",@"jack",@"gillchrist",@"jackson"];
EmpDictionary=[[NSMutableDictionary alloc]init];
[EmpDictionary setValue:@"martin" forKey:@"name"];
[EmpDictionary setValue:@"18" forKey:@"age"];
[EmpDictionary setValue:@"M" forKey:@"gender"];
[EmpDictionary setValue:@"9652893070" forKey:@"phoneNumber"];
[EmpArray addObject:EmpDictionary];
NSLog(@"emparray counr %d",[self.EmpArray count]);
[EmpDictionary setValue:@"jack" forKey:@"name"];
[EmpDictionary setValue:@"19" forKey:@"age"];
[EmpDictionary setValue:@"F" forKey:@"gender"];
[EmpDictionary setValue:@"96656893070" forKey:@"phoneNumber"];
[EmpArray addObject:EmpDictionary];
[EmpDictionary setValue:@"Louis" forKey:@"name"];
[EmpDictionary setValue:@"21" forKey:@"age"];
[EmpDictionary setValue:@"F" forKey:@"gender"];
[EmpDictionary setValue:@"9652893060" forKey:@"phoneNumber"];
[EmpArray addObject:EmpDictionary];
[EmpDictionary setValue:@"Gillchrist" forKey:@"name"];
[EmpDictionary setValue:@"23" forKey:@"age"];
[EmpDictionary setValue:@"M" forKey:@"gender"];
[EmpDictionary setValue:@"99998989" forKey:@"phoneNumber"];
[EmpArray addObject:EmpDictionary];
[super viewDidLoad];
}
- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath {
NSLog(@"creating cell in cell for row at index");
employeeCell *empcell = (employeeCell *)[tableView dequeueReusableCellWithIdentifier:@"empcell1"];
if(empcell==nil)
{
NSLog(@"In creating cell");
[[NSBundle mainBundle]loadNibNamed:@"employeeCell" owner:self options:nil];
empcell=tableCell;
}
for(int i=1;i<=3;i++)
{
NSLog(@"after creating cell");
//NSDictionary *temp=[self.EmpArray objectAtIndex:indexPath.row];
NSDictionary *temp = [self.EmpArray objectAtIndex:indexPath.row];
NSString *empname= [temp objectForKey:@"name"];
NSString *age= [temp objectForKey:@"age"];
//NSInteger age = [temp objectForKey:@"age"];
NSString *gender= [temp objectForKey:@"gender"];
NSString *phonenumber = [temp objectForKey:@"phoneNumber"];
empcell.EmpName.text=empname;
empcell.EmpAge.text=age;
empcell.EmpGender.text=gender;
empcell.EmpPhoneNumber.text=phonenumber;
empcell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
}
return empcell;
}