从另一个方法更新 UITableViewCell 中的值 iOS

Update value in UITableViewCell from another methd iOS

我有方法调用

- (void)redeemOfferService
{
  // in this method i want access OffersBoughtCellTableViewCell,
      how to access tableview cell here ?
  // want to update selected tableview cell values
  // here i am getting selected cell details in selectedOfferBoughtObj which 
     is actually NSObject in that i am having five string values  
     i want show that values in my tableview cell how can i ?
  //

}

以上方法调用自

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex 
{
    if(alertView.tag == 10)
    {
       if(buttonIndex == 0)
       {
        [self redeemOfferService];
       }
    }
}

当我点击表格视图单元格时调用此方法,即

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIAlertView *logoutAlert = [[UIAlertView alloc]initWithTitle:@"Are you sure you want to redeem?" message:nil delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:@"No", nil];
    logoutAlert.tag  = 10;
    [logoutAlert show];
}

我知道有办法,我们可以通过点击按钮发送发件人,但我想要在上面的场景中。

您肯定是在更新一些 NSMutableArray 的表视图,这意味着您正在用这个数组填充您的表视图。

在您的 redeemOfferService 方法中,更改 NSMutableArray 中用于填充表格视图的对象的值。 然后调用 [self.tableviewName reloadData]

在您的 class NSIndexPath 类型中使用全局变量,并在您选择的索引路径

中选择存储
NSIndexPath *selectedIndexPath; //declare it as a global

在 didSelect 中分配选定的值后

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath
{
UIAlertView *logoutAlert = [[UIAlertView alloc]initWithTitle:@"Are you sure you want to redeem?" message:nil delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:@"No", nil];
logoutAlert.tag  = 10;
[logoutAlert show];
selectedIndexPath = indexPath;
}

然后在你的函数中这样改变

    - (void)redeemOfferService
{
     OffersBoughtCellTableViewCell * _selectedCell = [offersTableView cellForRowAtIndexPath:selectedIndexPath]; //Now Its your selected cell Try this . 

}

它会很好地尝试一次并恢复原状

您可以使用 UITableViewindexPathForSelectedRow 属性 访问选定的 indexPath。

- (void)redeemOfferService
{
     OffersBoughtCellTableViewCell *selectedCell = (OffersBoughtCellTableViewCell *)[tableViewObject cellForRowAtIndexPath:offersTableView.indexPathForSelectedRow];
}

这会为您提供所选的 OffersBoughtCellTableViewCell