ios - PFRelation 在 Cell 上使用 UiButton 创建

标签 ios parse-platform relation

我正在尝试使用带有自定义单元格的 TableView 中的按钮创建 PFRelation,但我无法创建这些关系,我只创建与特定用户的关系,无论我选择哪个单元格。 ..

我哪里做错了?

    - (IBAction)FFAddAmiciAction:(id)sender {
             NSIndexPath *indexPath = [[self tableView] indexPathForSelectedRow];
            PFObject *searchedUser = [self.objects objectAtIndex:indexPath.row];
            PFUser *user = [PFUser currentUser  ];
             PFRelation *relation = [user relationforKey:@"Amic"];
               [relation addObject:searchedUser];
                 [user saveInBackground];
}

最佳答案

当您点击单元格上的按钮时,通常不会导致单元格被设置为已选择。这意味着当您调用 indexPathForSelectedRow 时,您经常会得到错误的结果。

您可能想考虑使用不同的方式来获取与按钮关联的行的索引路径,有很多潜在的选项,也许:

  1. 教导按钮有关索引路径的信息(可能使用 objc_setAssociatedObject)
  2. 使用indexPathForRowAtPoint:根据按钮中心点获取行(记得转换坐标空间)

输入后请检查语法和拼写...

CGPoint point = [(UIButton *)sender convertPoint:[(UIButton *)sender center] toView:[self tableView]];
NSIndexPath *indexPath = [[self tableView] indexPathForRowAtPoint:point];

关于ios - PFRelation 在 Cell 上使用 UiButton 创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19092647/

相关文章:

ios - 具有自定义类的iOS数组到具有NSString的数组

iphone - 在另一个 View 中显示一个 View 的预览

mysql - 关系数据库设计问题

sql - 理解插入异常的概念

gridview - Yii2 在 GridView 中使用 viaTable 关系进行排序和过滤

ios - Swift 中的协议(protocol)设计

ios - 在 CCRenderTexture 中绘制抗锯齿圆

javascript - 使用 Parse.com 云代码验证电话号码

ios - Parse.com 以编程方式向类添加一行

javascript - 在 uitableview 单元格中显示项目的评分