通过Web服务插入数据后重新加载TableView中的数据

时间:2014-04-08 11:15:07

标签: objective-c ios7

enter image description here

我正在使用JSON解析来上传UITableView中的数据。一切正常,但通过textView插入数据后,它在服务器上传,但在我之前和当前的UITableView中没有刷新。我需要重启我的项目才能看到上传的数据。我想在插入数据后重新加载UITableView。我使用[self.myTableView reloadData],但它无法在任何地方使用。

-(PrayerListCustomCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: 
  (NSIndexPath *)indexPath
 {
   static NSString *CellIdentifier = @"Cell";
    PrayerListCustomCell *cell = (PrayerListCustomCell *)[tableView 
           dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
         cell = [[[NSBundle mainBundle]loadNibNamed:@"PrayerListCustomCell" 
        owner:self options:nil]objectAtIndex:0];
 }

  cell.dateLbl.text = [dateList objectAtIndex:indexPath.row];
  cell.prayerLbl.text = [prayerList objectAtIndex:indexPath.row];
  return cell;
}
 -(void)submitClicked
{
if ([prayerTextView.text isEqualToString:@""]) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Please fill 
     your request in text box!" delegate:self cancelButtonTitle:@"OK"  
     otherButtonTitles:nil, nil];
    [alert show];
}
else
{
    prayerSubmitData = prayerTextView.text;
    SubmitPrayer *submit = [[SubmitPrayer alloc]init];
    [ASKevrOperationManager submitPrayer:submit handler:^(id object , NSError *error 
       , BOOL success)
     {
         if (success) {
             NSLog(@"this is request data = %@",object);
             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil 
              message:@"Successful upload!" delegate:nil cancelButtonTitle:@"OK" 
              otherButtonTitles:nil];
             [alert show];
             prayerTextView.text = @"";
             [self.requestTableView reloadData];
            //Do refreshment code
         }
         else
         {
             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil 
            message:@"Please try again later!" delegate:nil cancelButtonTitle:@"OK" 
             otherButtonTitles:nil];
             [alert show];
         }
     } ];
    }
  }

1 个答案:

答案 0 :(得分:1)

您需要将已提交的数据添加到prayerList数组中。这应该是这样的:

if (success) {
   // show alert

   [prayerList addObject:prayerTextView.text];
   [self.requestTableView reloadData];
   prayerTextView.text = @"";

   //Do refreshment code
}