didSelectRowAtIndexPath:(NSIndexPath *)indexPath我插入了一个alertView,其中包含一个根据单击的单元格而变化的文本。
按钮“SEND”nell'alertView的操作必须保存所选单元格中存在的标签内容。
P.S。我正在使用Parse.com
到目前为止一切正常但我只有一个问题,保存的数据不正确,因为它们不是所选单元格的数据,而是来自表格视图中第一个单元格的数据...我不保存更多。只有这个......
Nell'IndexPath'm做错了什么?你能帮我识别所选择的单元格吗?
- (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");
}
}
答案 0 :(得分: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");
}
}