2014-02-07 66 views
0

所以我有一个HistoryViewController,当我点击一个单元格时,我想要在DetailsViewController上获得那个精确点击单元格的值。这样,当用户点击我的DetailsViewController中的“付费”按钮时,我的HistoryViewController可以标记该特定单元“付费”。如何让选定的表格视图单元格在不同的视图上

编辑:

好了,在我的核心数据的数据模型我有两个实体。一个是PeopleYouOwe。另一个是PeopleWhoOweYou。每个实体都有一个名为“Paid”的属性。付费设置为键入BOOLEAN。当我点击我的HistoryTableViewController中的单元格时,它将我引导至我的DetailViewController。在我的DetailViewController中,我有一个叫做“Paid”的按钮。当用户点击这个按钮时,我想知道如何让被点击的单元格设置为YES。之后,我想在CoreData中更新我的所有实体,以便将BOOLEAN值“Paid”的所选单元格的属性保存为YES。

回答

0

你可以添加一个回调块物业给你DetailViewController

@property (copy, readwrite, nonatomic) void (^payButtonActionHandler)(BOOL didPay) 

如果您想创建某种切换,didPay参数很有用。

而在你DetailViewController实现:

- (void)paidButtonAction:(UIButton *)sender { 

    if (self.payButtonActionHandler) 
     self.payButtonActionHandler(YES); 
} 


在你HistoryViewController

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

     Person *person = // get your person object for this row 
     DetailsViewController *vc = [DetailsViewController new]; 
     vc.payButtonActionHandler = ^(BOOL didPay) { 

      // Update your entity 
      person.hasPaid = didPay; 

      // Reload the row 
      [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; 
     } 
     [self.navigationController pushViewController:vc animated:YES]; 
    } 



编辑:您可以检查这个网站记住块语法http://fuckingblocksyntax.com/

+0

我的历史视图控制器是TableViewController。我的DetailsViewController是常规视图 – doc92606

+0

刚编辑我的答案,让我知道如果这有效。 – jbouaziz

+0

所以我可以设置ID对象= [YouOweArray objectAtIndex:indexPath.row]是否正确? – doc92606

0

您需要在您的DetailsViewController中创建与“value”相同类型的属性。当用户点击单元格时,在didSelectRowAtIndexPath方法上,将该值传递给您的DetailsViewController实例。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // ... 
    MyObject *object = //.... get the value for that row 
    myDetailsViewController.myselectedObject = object; 
    // myDetailsViewController is the instance of the detailsViewController 
    // ... 
} 

所以,在DetailsViewController你的代码,你可以操纵使用

[self myselectedObject] 

例如,用于支付按钮对象,你可以设置

self.myselectedObject.paid = YES; //... or whatever you want to do 
相关问题