如何在一个字符串中获取 UITableView 的选定单元格的值 [英] How to get the values of selected cells of a UITableView in one string

查看:61
本文介绍了如何在一个字符串中获取 UITableView 的选定单元格的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很确定这真的很简单.但我无法完成这项工作.由于他们的 FBID,我有一个 UITableView,我可以在其中动态显示 Facebook 好友列表.基本上,我想返回我选择的朋友的 FBID,用逗号分隔的一个字符串.如果可能,在 IBAction 中,我可以将它们传递给 php 的参数.例如,假设我有 4 个朋友的列表,A B C D,他们的 id 是 1,2,3,4.如果我选择 A 和 C,我想要一个表示 1,3 的字符串.

i'm pretty sure this is really simple. But i can't get to make this work. I have a UITableView where i display dynamically a list of facebook friends, thanks to their FBID. Basically, i would like to return the FBIDs of the friends i selected, in one string separated with commas. If possible, in a IBAction, so i can pass them into parameters of a php. For example, let's pretend i have a list of 4 friends, A B C D, and their ids are 1,2,3,4. If i select A and C, i would like to have a string which says 1,3.

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

All i managed to do is to display the id of the friend i select, one at a time. Here's my code :

-(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);


}

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

Thank you in advance, i'm sure this is not complicated.

推荐答案

-(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
}

这篇关于如何在一个字符串中获取 UITableView 的选定单元格的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆