如何在一个字符串中获取UITableView的选定单元格的值

0 objective-c uitableview nsstring didselectrowatindexpath ios

我很确定这很简单.但我无法做到这一点.我有一个UITableView,我可以动态显示Facebook好友列表,这要归功于他们的FBID.基本上,我想返回我选择的朋友的FBID,用逗号分隔的一个字符串.如果可能的话,在IBAction中,所以我可以将它们传递给php的参数.例如,让我假装我有4个朋友的列表,ABCD,他们的ID是1,2,3,4.如果我选择A和C,我希望有一个字符串,表示1,3.

我设法做的就是显示我选择的朋友的ID,一次一个.这是我的代码:

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

rowcount = [[tableView indexPathsForSelectedRows] count];
indexer = [idFriends objectAtIndex:indexPath.row];
aapell = [NSString stringWithFormat:@"%@", indexer];

NSMutableString * arrayIds = [[NSMutableString alloc] init];
[arrayIds appendString:aapell];

NSLog(@"ids: %@", arrayIds);


}
Run Code Online (Sandbox Code Playgroud)

提前谢谢你,我确信这并不复杂.

Tom*_*voy 6

-(IBAction)gatherFBIds
{
    NSString *listOfFacebookIDs = @"";
    NSArray *indexPathArray = [self.tableView indexPathsForSelectedRows];
    for(NSIndexPath *index in indexPathArray)
    {
        //Assuming that 'idFriends' is an array you've made containing the id's (and in the same order as your tableview)
        //Otherwise embed the ID as a property of a custom tableViewCell and access directly from the cell
        //Also assuming you only have one section inside your tableview
        NSString *fbID = [idFriends objectAtIndex:index.row];
        if([indexPathArray lastObject]!=index)
        {
            listOfFacebookIDs = [listOfFacebookIDs stringByAppendingString:[fbID stringByAppendingString:@", "]];
        }
        else
        {
            listOfFacebookIDs = [listOfFacebookIDs stringByAppendingString:fbID];

        }
    }

    NSLog(@"Your comma separated string is %@",listOfFacebookIDs);
    //Now pass this list to wherever you'd like
}
Run Code Online (Sandbox Code Playgroud)