简体   繁体   中英

how to refresh tableview after soap request in iOS

i am retrieving data from core data and displaying it on tableview,i have another viewController which shows details of selected row from the tableview.from that viewController i am sending soap request,what i want to do is after sending request i want that selected row should be deleted from the tableview.i don't know how to do this.sorry if i am not making any sense,any help is welcomed.

my code for tableview controller

     - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString*cellTableIdentifier=@"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellTableIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellTableIdentifier];
}

self.pendingTable.bounces = YES;
cell.accessoryType =  UITableViewCellAccessoryDisclosureIndicator;
// Configure the cell...
NSManagedObject *webDetail= [self.detailWebServce objectAtIndex:indexPath.row];
NSString*results=[[NSString alloc]initWithFormat:@"%@",[webDetail valueForKey:@"username"]];
cell.imageView.image=[UIImage imageWithData:[webDetail valueForKey:@"images"]];

NSString*date=[[NSString alloc]initWithFormat:@"%@",[webDetail valueForKey:@"currentDate"]];
[cell.detailTextLabel setText:date];
[cell.textLabel setText:results];

return cell;

}

pragma tableview delegates

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

    DetailComplaints *detailComplaints = [[UIStoryboard storyboardWithName:@"Main" bundle:nil]
                             instantiateViewControllerWithIdentifier:@"DetailComplaints"];
    detailComplaints.tempWebData=[self.detailWebServce objectAtIndex:indexPath.row];


    [self.navigationController pushViewController:detailComplaints animated:YES];

       [self dismissViewControllerAnimated:NO completion:nil];
}

需要使用UITableView's reloadData方法重新加载tableview中的内容,但首先需要update tablview's datasource数组或字典。

[YourTableViewHere reloadData]

From the Documentation:

Declaration OBJECTIVE-C

  - (void)reloadData

Discussion

Call this method to reload all the data that is used to construct the table, including cells, section headers and footers, index arrays, and so on. For efficiency, the table view redisplays only those rows that are visible. It adjusts offsets if the table shrinks as a result of the reload. The table view's delegate or data source calls this method when it wants the table view to completely reload its data. It should not be called in the methods that insert or delete rows, especially within an animation block implemented with calls to beginUpdates and endUpdates.

You can call [self.tableView reloadData] to refresh your table view.

If you want to do this on main thread:

 dispatch_async(dispatch_get_main_queue(), ^{ [self.tableView reloadData]; });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM