无法在我的UITableView中查看数据

时间:2014-11-13 22:03:08

标签: ios uitableview

我无法在UITableView中查看我的数据,我的UITableViewcell中有四个标签,我试图从我的网络服务中获取数据。在升级到IOS 8之前它曾经工作正常,在IOS 8中工作后,应用程序无法显示数据。我需要指定的另一件事是,当我从网络浏览器插入数据时,我能够看到我的应用程序在UITableView中的记录,当我使用此应用程序插入数据时,我无法显示记录。我发现Web服务和我的数据库没有问题。因为我在URL中输入数据时能够看到数据。以下是代码:

NSHTTPURLResponse *response = nil;
    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url
                                                cachePolicy:NSURLRequestReturnCacheDataElseLoad
                                            timeoutInterval:30];


    // Make synchronous request
    urlData = [NSURLConnection sendSynchronousRequest:urlRequest
                                    returningResponse:&response
                                                error:&error];
    if ([response statusCode] >= 200 && [response statusCode] < 300)
    {
        NSString *responseDatatest = [NSJSONSerialization JSONObjectWithData:urlData
                                                                 options:NSJSONReadingAllowFragments error:&error];
        NSLog(@"responseDatatest : %@",responseDatatest);

        NSArray *entries = [NSJSONSerialization JSONObjectWithData:[responseDatatest dataUsingEncoding:NSUTF8StringEncoding]
                                                           options:0 error:&error];
        NSLog(@"Entries : %@", entries);
        if(!entries)
        {
            NSLog(@"Error : %@", error);
        }
        else{

            for (NSDictionary *entry in entries) {
                projectNames = [entries valueForKey:@"NM_PROJECT"];
                taskNames = [entries valueForKey:@"TASk_NAME"];
                subtaskNames = [entries valueForKey:@"SUBTASK_NAME"];
                timesheetid = [entries valueForKey:@"ID_TIMESHEET_DTLS"];
                projId = [entries valueForKey:@"ID_PROJECT"];
                taskId = [entries valueForKey:@"ID_TASK"];
                subtaskId = [entries valueForKey:@"ID_SUB_TASK"];
                totalhours = [entries valueForKey:@"No_Hours"];
                approve = [entries valueForKey:@"FL_APPROVE"];
                leaves = [entries valueForKey:@"NM_LEAVE"];
            }
            NSInteger sumArray = [[totalhours valueForKeyPath:@"@sum.integerValue"] floatValue];
            NSInteger approved = [[approve valueForKeyPath:@"@sum.integerValue"] intValue];
            NSLog(@"sumArray : %f", [[totalhours valueForKeyPath:@"@sum.integerValue"] floatValue]);
            NSLog(@"approve : %ld", approved);
            NSLog(@"subtask : %@", subtaskNames);
        }

    }       else {

    }
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [projectNames count];

}

-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identitifier = @"Cell";
    TableViewCell * cell = [tableView
                                 dequeueReusableCellWithIdentifier:identitifier
                                 forIndexPath:indexPath];
    if ([[[timesheetid objectAtIndex:indexPath.row] stringValue] isEqualToString:@"0"])
    {
        cell.lblProjects.text = [NSString stringWithFormat:@"%@",@"No Projects Filled"];
        cell.lblTasks.text = [NSString stringWithFormat:@"%@",@"No Tasks Filled"];
        cell.lblSubTasks.text = [NSString stringWithFormat:@"%@",@"No SubTasks Filled"];
        cell.lblHours.text = [NSString stringWithFormat:@"%@",@"0 Hours Filled"];
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    else if ([[leaves objectAtIndex:indexPath.row] isEqualToString:@"0"])
    {
        cell.lblProjects.text = [projectNames objectAtIndex:indexPath.row];
        cell.lblTasks.text = [taskNames objectAtIndex:indexPath.row];
        cell.lblSubTasks.text = [subtaskNames objectAtIndex:indexPath.row];
        cell.lblHours.text = [[totalhours objectAtIndex:indexPath.row] stringValue];
        //NSLog(@"cell :%@",cell.lblHours.text);
    }
    else
    {
        cell.lblProjects.text = [leaves objectAtIndex:indexPath.row];
        cell.lblTasks.text = [NSString stringWithFormat:@"%@",@"No Projects/Tasks on this Date"];
        cell.lblSubTasks.text = [NSString stringWithFormat:@"%@",@"No Sub Tasks on this Date"];
        cell.lblHours.text = [[totalhours objectAtIndex:indexPath.row] stringValue];
    }
    cell.editingAccessoryType =  UITableViewCellAccessoryDetailDisclosureButton;
    NSNumber *myProjectArrayString = [timesheetid objectAtIndex:indexPath.row];
    cell.hdbrowcount = [NSString stringWithFormat:@"%@",myProjectArrayString];

    return cell;


}

0 个答案:

没有答案