简体   繁体   English

为什么在显示此表视图时看到崩溃?

[英]Why am I seeing a crash when displaying this table view?

I am designing a simple navigation based application for EmployeeContactDirectory. 我正在为EmployeeContactDirectory设计一个基于导航的简单应用程序。 I am displaying the list of Employee. 我正在显示员工列表。 For showing the list of employee, I am using the restfull webservice. 为了显示员工列表,我使用了restfull Web服务。 I am getting proper response as I want. 我得到了适当的回应。 I have a utility class for Employee Data, class is EmployeeData.h and Employee.m (contains employeeId , employeeFirstName, employeeLastName). 我有一个用于Employee Data的实用程序类,该类是EmployeeData.h和Employee.m(包含employeeId,employeeFirstName和employeeLastName)。 My code for parsing 我的解析代码

// 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;
    }

I am getting the message (Exc_bad_Access) when this line of code comes into the execution flow: 这行代码进入执行流程时,我收到消息(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);

So, Please tell me how can I set the data into the tableview when I am using NSDictionary. 因此,请告诉我使用NSDictionary时如何将数据设置到表视图中。 When, user clicks on the row of the tableview it will return the id of the selected employee. 当用户单击表视图的行时,它将返回所选员工的ID。

Instead of the line 代替线

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

try the following, 试试以下,

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

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

Since it is autoreleased, it might have been out of memory. 由于它是自动释放的,因此它可能内存不足。

you need to implement a tableView delegate method called 您需要实现一个名为的tableView委托方法

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

here you will get the section & row clicked in the table 在这里,您将在表中单击该节和行

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在表视图中添加一行时,为什么我的应用程序崩溃? - Why does my app crash when I add an row to the table view? 当我向表格视图添加插入行时,为什么我的应用程序崩溃了? - Why does my app crash when I add an insert row to my table view? 在使用Core Plot构建iPhone应用程序时,为什么会看到以下链接器错误? - Why am I seeing the following linker errors when building an iPhone app with Core Plot? 在为Pebble手表进行开发时,为什么在iOS上的-setAppUUID:上看到错误? - Why am I seeing an error on -setAppUUID: on iOS when developing for the Pebble watch? 为什么会看到错误“格式不是字符串文字且没有格式参数”? - Why am I seeing the error “Format is not a string literal and no format arguments”? 为什么我看到有关NSAutoreleasePool不可用的消息警告? - Why am I seeing a message warning about NSAutoreleasePool being unavailable? 为什么在我的应用程序中看到以下异常? - Why am I seeing the following exception within my application? 为什么我在 cellForRowAtindexpath 中遇到崩溃? - Why am I experiencing a crash in cellForRowAtindexpath? 为什么在OS 3.1上的应用程序中看不到加载屏幕,但在4.0上却显示? - Why am I not seeing a loading screen in my application on OS 3.1, but I am on 4.0? iPhone-当视图映射正确时,为什么会出现此错误? - iPhone - Why am I getting this error when the view mapping is correct?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM