2012-01-05 1 views
0

Я разрабатываю простую навигационную программу для EmployeeContactDirectory. Я показываю список Employee. Для показа списка сотрудников я использую restfull webservice. Я получаю правильный ответ, как хочу. У меня есть класс утилиты для Employee Data, класс - EmployeeData.h и Employee.m (содержит employeeId, employeeFirstName, employeeLastName). Мой код для разбораПочему я вижу сбой при отображении этого вида таблицы?

// Code for parsing the response and getting desired field into the dictionary object and add the dictionaries into the array.  
    -(void)finishedReceivingData:(NSData *)data { 
     NSData *dataRes = [[restConnection stringData] dataUsingEncoding:NSUTF8StringEncoding]; 
     ////////////////Parsing with XPathQuery Start////////////////////// 
     if (dataRes != NULL) { 
     employeeData = [[EmployeeData alloc] init]; 
     NSString *xPathQuery = [NSString stringWithFormat:@"/*",employeeData.employeeID]; 
     NSArray *arrayWithObjectList = PerformXMLXPathQuery(dataRes, xPathQuery); 
     for(NSDictionary *childOfObjectList in arrayWithObjectList){ 
     NSArray *arrayOfDataValueObj = (NSArray *)[childOfObjectList objectForKey:@"nodeChildArray"]; 
     for(NSDictionary *childObjListDict in arrayOfDataValueObj){ 
     NSArray *childObjListDataValue = (NSArray *)[childObjListDict objectForKey:@"nodeChildArray"]; 
     for(NSDictionary *childDict in childObjListDataValue){ 
    if([[childDict objectForKey:@"nodeName"] isEqualToString:@"FName" ]) 
     { 
     employeeData.employeeFirstName = [childDict objectForKey:@"nodeContent"]; 
     } 
     if([[childDict objectForKey:@"nodeName"] isEqualToString:@"EmpID"]) 
     { 
     employeeData.employeeID = [childDict objectForKey:@"nodeContent"]; 
     } 
     } 
     //employeeFirstNameArray = [NSArray arrayWithObjects:employeeData, nil]; 
     employeeIDArray = [NSArray arrayWithObjects:employeeData, nil]; 
     dictionaryEmployeeFirstName = [NSDictionary dictionaryWithObject:employeeData.employeeFirstName forKey:@"employeeData"]; 
     dictionaryEmployeeID = [NSDictionary dictionaryWithObject:employeeData.employeeID forKey:@"employeeData"]; 
     tempArray = [NSArray arrayWithObjects:dictionaryEmployeeFirstName, dictionaryEmployeeID, nil]; 
     NSLog(@"size of temp %d",[tempArray count]); 
     } 
     } 
     //[employeeData release]; 
     //employeeData = nil; 
     } 
     [self.tableviewEmloyeeList reloadData]; 
    //////////////////////////////Parsing with XPathQuery end////////// 
    } 


    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
     static NSString *CellIdentifier = @"Cell"; 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     } 
     // Configure the cell.. 
     NSDictionary *dictionaryEmployee = [tempArray objectAtIndex:indexPath.row]; 
     NSArray *firstNameArray = [dictionaryEmployee objectForKey:@"employeeData"]; 
     NSString *cellValue = [firstNameArray objectAtIndex:indexPath.row]; 
     NSLog(@"cellValue %@",cellValue); 
     cell.textLabel.text = cellValue; 

     return cell; 
    } 

Я получаю сообщение (EXC_BAD_ACCESS), когда эта строка кода приходит в поток выполнения:

NSDictionary *dictionaryEmployee = [tempArray objectAtIndex:indexPath.row] 

The EXC_Bad_Access is at the mail.m file at line nt retVal = UIApplicationMain(argc, argv, nil, nil); 

Так, пожалуйста, скажите мне, как я могу установить данные в tableview, когда я использую NSDictionary. Когда пользователь нажимает на строку таблицы, он возвращает идентификатор выбранного сотрудника.

ответ

0

Вместо линии

tempArray = [NSArray arrayWithObjects:dictionaryEmployeeFirstName, dictionaryEmployeeID, nil]; 

попробовать следующее,

if(tempArray) 
{ 
    [tempArray release]; 
    tempArray = nil; 
} 

tempArray = [[NSArray arrayWithObjects:dictionaryEmployeeFirstName, dictionaryEmployeeID, nil] retain]; 

Так как autoreleased, это может быть из памяти.

0

вам нужно реализовать метод Tableview делегата под названием

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

здесь вы получите раздел & строки щелкнул в таблице

Смежные вопросы