【问题标题】:NSIndexPath not working on DidSelectedRow with AlertView FunctionNSIndexPath 不适用于具有 AlertView 功能的 DidSelectedRow
【发布时间】:2013-11-14 19:43:29
【问题描述】:

在 tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath 我插入了一个 alertView,其中包含一个文本,该文本会根据单击的单元格而变化..

“发送”按钮的动作 nell'alertView 必须保存所选单元格中存在的标签内容。

附:我正在使用 Parse.com

到目前为止,一切正常,但我只有一个问题,保存的数据不正确,因为它们不是所选单元格的数据,而是表格视图中第一个单元格的数据......我没有保存更多。 . 只有这个..

Nell'IndexPath' 做错了什么?你能帮我识别选中的单元格all'alertview吗?

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{


    if ( buttonIndex ==0) {

        NSLog(@"ritorno");

    }

    else {

        NSArray *indexes = [self.TableView indexPathsForSelectedRows];
        for (NSIndexPath *indexPath in indexes) {

            PFUser *user = [self.Utenti objectAtIndex:indexPath.row];
            PFObject *RichiestaAmicizia = [PFObject objectWithClassName:FF_AMICIZIE_CLASS];
            [RichiestaAmicizia setObject:[PFUser currentUser] forKey:FF_AMICIZIE_DA_USER];
            [RichiestaAmicizia setObject:user forKey:FF_AMICIZIE_A_USER];
            [RichiestaAmicizia setObject:@"In_Attesa" forKey:FF_AMICIZIE_STATO];
            [RichiestaAmicizia saveInBackground];

        }

   NSLog(@"Send");
}

}

【问题讨论】:

  • 是否要获取所有选定的行?还是只有一个?被点击的那个?
  • 我希望当我点击发送(nell'alertView)时,保存的数据是正确单元格的数据。

标签: ios uitableview uialertview didselectrowatindexpath nsindexpath


【解决方案1】:

如果我理解正确:

创建实例变量:

NSInteger _clickedCell;

然后

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    _clickedCell = indexPath.row;
    ....
}



- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if ( buttonIndex ==0) {

        NSLog(@"ritorno");

    }
    else {
        PFUser *user = [self.Utenti objectAtIndex:_clickedCell];
        PFObject *RichiestaAmicizia = [PFObject objectWithClassName:FF_AMICIZIE_CLASS];
        [RichiestaAmicizia setObject:[PFUser currentUser] forKey:FF_AMICIZIE_DA_USER];
        [RichiestaAmicizia setObject:user forKey:FF_AMICIZIE_A_USER];
        [RichiestaAmicizia setObject:@"In_Attesa" forKey:FF_AMICIZIE_STATO];
        [RichiestaAmicizia saveInBackground];
        NSLog(@"Send");
    }
}

【讨论】:

  • 我试过了,但没有用……我保存了 TableView 中第一个单元格的数据,而不是选定的单元格……:(我不明白
  • 我需要更多信息。 self.Utenti 包含在您的 tableView 中填充的数据?您有超过 1 个部分吗?
  • 你的方法是我会做的......逻辑方法是正确的...... Self.Utenti 是包含从数据库中获取并显示在 TableView 中的所有对象的数组。 . 是应用程序的订阅者列表 .... TableView 很简单 ... 没有其他部分
猜你喜欢
  • 2015-11-27
  • 2015-04-19
  • 2021-04-28
  • 1970-01-01
  • 1970-01-01
  • 2014-10-12
  • 1970-01-01
  • 1970-01-01
  • 2016-11-19
相关资源
最近更新 更多