Ios 无法重新加载UItableview

Ios 无法重新加载UItableview,ios,uitableview,reloaddata,Ios,Uitableview,Reloaddata,我的UITableView中有一些数据,有四个标签:项目、任务、子任务和小时,我将数据从后端更改为数据库,并更改了数据。我把小时数从12小时改为10小时。但我在UITableView中只看到了12小时的旧数据,而不是10小时。有人能提出这背后的原因吗。我试图清理、重新启动未加载数据库中正确数据的计算机。我可以补充的另一件事是,我在web服务的帮助下检索数据。以及将数据从JSONSerialization格式转换为NSArray。当我在浏览器URL中ping我的web服务时,它会提供正确的数据。以

我的UITableView中有一些数据,有四个标签:项目、任务、子任务和小时,我将数据从后端更改为数据库,并更改了数据。我把小时数从12小时改为10小时。但我在UITableView中只看到了12小时的旧数据,而不是10小时。有人能提出这背后的原因吗。我试图清理、重新启动未加载数据库中正确数据的计算机。我可以补充的另一件事是,我在web服务的帮助下检索数据。以及将数据从JSONSerialization格式转换为NSArray。当我在浏览器URL中ping我的web服务时,它会提供正确的数据。以下是代码:

- (void)viewDidLoad
{

    [super viewDidLoad];

    [self loadprojects];


}

NSString *strwebsite = [[NSUserDefaults standardUserDefaults] valueForKey:@"website"];
    NSString *websitemethods = @"Timesheet.svc/GetTimesheet";
    NSString *projecturltemp = [strwebsite stringByAppendingString:websitemethods];
    NSString *str = [[NSUserDefaults standardUserDefaults] valueForKey:@"UserLoginIdSession"];
    NSString *usrid = str;
    NSString * projecturl =[NSString stringWithFormat:@"%@/%@/%@",projecturltemp,usrid,eventDate];
    NSURL *url = [NSURL URLWithString:projecturl];
    [self.tableView reloadData];
    NSLog(@"url : %@", url);
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];




    NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/projectpicker" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/jsonArray" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];


    NSError *error = [[NSError alloc] init];
    NSHTTPURLResponse *response = nil;
    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    //NSLog(@"urlData : %@",urlData);
    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"];
            }
        }

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


}
我看不到这条线


[self.tableview重载数据]

在更改数据时使用postnotification。
[[NSNotificationCenter defaultCenter]postNotificationName:@refresh object:self]

我添加了同一行,但无法刷新数据。让我编辑这个问题,检查发送重新加载数据后是否调用了cellForRowAtIndexPath。如果是,则说明您没有正确更新数据结构。为什么要在单独的方法中调用重载数据?为什么不在处理NSURLRequest后立即调用它呢?是的,我在reloaddata[在NSURLRequest下面]保留了一个断点,在cellForIndexPath保留了一个断点,首先命中的断点是reloaddata,然后转发到cellForIndexPath。您确定url请求正在更新存储的数据吗。如果调用CellForRowatineXpath,则表示CellForRowatineXpath使用的数据错误。