Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用从后端获取的阵列设置UITableView标记?_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 如何使用从后端获取的阵列设置UITableView标记?

Ios 如何使用从后端获取的阵列设置UITableView标记?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我使用UITableView中的复选标记选择语言,并在更新配置文件时将这些语言传递到后端。 现在,当我再次与用户登录时,我也会从选择中获得更新的语言。因此,我想根据来自后端的语言在UITableview中显示刻度。怎么可能呢 - (void)viewDidLoad { [super viewDidLoad]; arrProductSelection = [[NSMutableArray alloc]initWithObjects:@"Afar",@"Abkhazian",

我使用UITableView中的复选标记选择语言,并在更新配置文件时将这些语言传递到后端。 现在,当我再次与用户登录时,我也会从选择中获得更新的语言。因此,我想根据来自后端的语言在UITableview中显示刻度。怎么可能呢

    - (void)viewDidLoad
{
    [super viewDidLoad];
    arrProductSelection = [[NSMutableArray alloc]initWithObjects:@"Afar",@"Abkhazian",@"Afrikaans",@"Amharic",@"Arabic",@"Assamese",@"Aymara",@"Azerbaijani",@"Bashkir",@"Belarusian",@"Bulgarian",@"Bihari",@"Bislama",@"Bengali",@"Bislama",@"Tibetan",@"Breton",@"Bosnian",@"Catalan",@"Cebuano",@"Cherokee",@"Corsican",@"Seselwa",@"Czech",@"Welsh",@"Danish",@"German",@"Dhivehi",@"Dzongkha",@"Greek",@"English",@"Esperanto",@"Spanish",@"Estonian",@"Basque",@"Persian",@"Finnish",@"Fijian",@"Faroese",@"French",@"Frisian",@"Irish",@"Scots Gaelic",@"Galician",@"Guarani",@"Gujarati",@"Manx",@"Hausa",@"Hawaiian",@"Bislama",@"Hindi",@"Hmong",@"Croatian",@"Haitian Creole",@"Hungarian",@"Armenian",@"Interlingua",@"Indonesian",@"Igbo",@"Inupiak",@"Icelandic",@"Italian",@"Inuktitut",@"Hebrew",@"Japanese",@"Javanese",@"Georgian",@"Khasi",@"Kazakh",@"Greenlandic",@"Khmer",@"Kannada",@"Korean",@"Kashmiri",@"Kurdish",@"Kyrgyz",@"Latin",@"Luxembourgish",@"Ganda",@"Limbu",@"Lingala",@"Laothian",@"Lithuanian",@"Latvian",@"Malagasy",@"Mauritian Creole",@"Malagasy",@"Maori",@"Macedonian",@"Malayalam",@"Mongolian",@"Marathi",@"Malay",@"Maltese",@"Burmese",@"Nauru",@"Nepali",@"Dutch",@"Norwegian",@"Ndebele",@"Pedi",@"Nyanja",@"Occitan",@"Oromo",@"Oriya",@"Punjabi",@"Polish",@"Pashto",@"Portuguese",@"Quechua",@"Rhaeto Romance",@"Scots",@"Sindhi",@"Sango",@"Sinhalese",@"Slovak",@"Slovenian",@"Samoan",@"Shona",@"Somali",@"Albanian",@"Serbian",@"Siswant",@"Sesotho",@"Sundanese",@"Swedish",@"Swahili",@"Syriac",@"Tamil",@"Telugu",@"Tajik",@"Thai",@"Tigrinya",@"Turkmen",@"Tagalog",@"Sundanese",@"Tswana",@"Tonga",@"Turkish",@"Tsonga",@"Tatar",@"Uighur",@"Ukrainian",@"Urdu",@"Uzbek",@"Venda",@"Vietnamese",@"Volapuk",@"Waray Philippines",@"Wolof",@"Xhosa",@"WYiddish",@"Yoruba",@"WZhuang",@"Chinese",@"Hant,Chinese",@"Zulu",nil];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)viewWillAppear:(BOOL)animated
{
    [languageTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:0];
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    arrayFetchFromDefaults = [userDefaults objectForKey:@"selectedcheckmark"];
    arrProductSelectDeSelectCheckMark = [[NSMutableArray alloc]initWithArray:arrayFetchFromDefaults];
    NSLog(@"Array from defaults %@",arrayFetchFromDefaults);
    if(arrProductSelectDeSelectCheckMark.count == 0)
    {
        arrProductSelectDeSelectCheckMark = [[NSMutableArray alloc]init];
        for(int j=0;j<[arrProductSelection count];j++)
        {
            [arrProductSelectDeSelectCheckMark addObject:@"deselected"];

        }
    }

    NSMutableArray *arrSelected = [[NSMutableArray alloc] init];
    for (int i= 0;i< arrayFetchFromDefaults.count ;i++ )
    {
        if([[arrayFetchFromDefaults objectAtIndex:i] isEqualToString:@"selected"])
        {
            NSLog(@"array array %@",[arrProductSelection objectAtIndex:i]);
            [arrSelected addObject:arrProductSelection[i]];
        }

    }

    self.strSelected = [arrSelected componentsJoinedByString:@","];

    NSLog(@"%@", _strSelected);
    //[self gatherFBIds];
    [languageTableView reloadData];
}

#pragma mark - UITableViewDataSource Methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return arrProductSelection.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *strCell = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strCell];
    if(cell==nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strCell];
    }
    if([[arrProductSelectDeSelectCheckMark objectAtIndex:indexPath.row] isEqualToString:@"deselected"])
        cell.accessoryType = UITableViewCellAccessoryNone;
    else
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    cell.textLabel.text = [arrProductSelection objectAtIndex:indexPath.row];
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.backgroundColor = [UIColor clearColor];
    cell.tintColor = [UIColor greenColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSMutableArray *arrSelected = [[NSMutableArray alloc] init];
    for (int i= 0;i< arrayFetchFromDefaults.count ;i++ )
    {
        if([[arrayFetchFromDefaults objectAtIndex:i] isEqualToString:@"selected"])
        {
            NSLog(@"array array %@",[arrProductSelection objectAtIndex:i]);
            [arrSelected addObject:arrProductSelection[i]];
        }

    }

    self.strSelected = [arrSelected componentsJoinedByString:@","];

    NSLog(@"%@", _strSelected);
   // [self gatherFBIds];
    return cell;
}

#pragma mark - UITableViewDelegate Methods
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];


    @try
    {
        CGPoint touchPoint = [cell convertPoint:CGPointZero toView:languageTableView];
        NSIndexPath *indexPath = [languageTableView indexPathForRowAtPoint:touchPoint];
        NSLog(@" Check mark %@",arrProductSelectDeSelectCheckMark);
        if([arrProductSelectDeSelectCheckMark count]==0)
        {
            for(int i=0; i<[arrProductSelection count]; i++)
            {
                [arrProductSelectDeSelectCheckMark addObject:@"deselected"];
            }
        }
        if([[arrProductSelectDeSelectCheckMark objectAtIndex:indexPath.row] isEqualToString:@"deselected"])
        {
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
            [arrProductSelectDeSelectCheckMark replaceObjectAtIndex:indexPath.row withObject:@"selected"];
             NSLog(@" Check mark 1 %@",arrProductSelectDeSelectCheckMark);
            NSMutableArray *arrSelected = [[NSMutableArray alloc] init];
            for (int i= 0;i< arrProductSelectDeSelectCheckMark.count ;i++ )
            {
                if([[arrProductSelectDeSelectCheckMark objectAtIndex:i] isEqualToString:@"selected"])
                {
                    NSLog(@"array array %@",[arrProductSelection objectAtIndex:i]);
                    [arrSelected addObject:arrProductSelection[i]];
                }

            }

            self.strSelected = [arrSelected componentsJoinedByString:@","];

            NSLog(@"%@", _strSelected);
        }
        else
        {
            cell.accessoryType = UITableViewCellAccessoryNone;
            [arrProductSelectDeSelectCheckMark replaceObjectAtIndex:indexPath.row withObject:@"deselected"];
             NSLog(@" Check mark 2 %@",arrProductSelectDeSelectCheckMark);

            NSMutableArray *arrSelected = [[NSMutableArray alloc] init];
            for (int i= 0;i< arrProductSelectDeSelectCheckMark.count ;i++ )
            {
                if([[arrProductSelectDeSelectCheckMark objectAtIndex:i] isEqualToString:@"selected"])
                {
                    NSLog(@"array array %@",[arrProductSelection objectAtIndex:i]);
                    [arrSelected addObject:arrProductSelection[i]];
                }

            }

            self.strSelected = [arrSelected componentsJoinedByString:@","];

            NSLog(@"%@", _strSelected);
        }

        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:arrProductSelectDeSelectCheckMark forKey:@"selectedcheckmark"];
        [defaults synchronize];




    }
    @catch (NSException *exception) {
        NSLog(@"The exception is-%@",exception);
    }


}
-(void)viewDidLoad
{
[超级视图下载];
arrProductSelection=[[NSMutableArray alloc]init,包含以下对象:@“阿法尔”、“阿布哈兹”、“南非荷兰语”、“阿姆哈拉语”、“阿拉伯语”、“阿萨姆语”、“艾马拉语”、“阿塞拜疆语”、“巴什基尔语”、“白俄罗斯语”、“保加利亚语”、“比哈里语”、“比斯拉马语”、“孟加拉语”、“比斯拉马语”、“藏语”、“布雷顿语”、“波斯尼亚语”、“加泰罗尼亚语”、“塞布奥卡诺语”、“切诺基语”、“捷克语”、“威尔士语”“德语”、“迪维希语”、“宗喀语”、“希腊语”、“英语”、“世界语”、“西班牙语”、“爱沙尼亚语”、“巴斯克语”、“波斯语”、“芬兰语”、“斐济语”、“法罗语”、“法语”、“弗里斯亚语”、“爱尔兰语”、“苏格兰盖尔语”、“加利西亚语”、“瓜拉尼语”、“古吉拉特语”、“曼克斯语”、“豪萨语”、“夏威夷语”、“比斯拉马语”、“海地语”、“匈牙利语”、“克罗地亚语”、“匈牙利语”@“语际语”、“印尼语”、“伊博语”、“因努皮亚克语”、“冰岛语”、“意大利语”、“因纽特人”、“希伯来语”、“日语”、“爪哇语”、“格鲁吉亚语”、“哈西语”、“哈萨克语”、“格陵兰语”、“高棉语”、“卡纳达语”、“韩语”、“克什米尔语”、“库尔德语”、“吉尔吉斯语”、“拉丁语”、“卢森堡语”、“甘达语”、“利姆布语”、“毛里塔尼亚语”、“拉脱维亚语”、“克里特语”“马达加斯加”和“,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,“@”斯洛文尼亚语“@“萨摩亚”是“萨摩亚”的。“萨摩亚”是“萨摩亚”的,”。“。“手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手手英国“,@“瓦莱菲律宾”,@”“沃洛夫”、“科萨”、“维德迪什”、“约鲁巴”、“吴庄”、“中国”、“汉特、中国”、“祖鲁”、“无”;
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
-(无效)视图将显示:(BOOL)动画
{
[languageTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0第0节]动画:无滚动位置:0];
NSUserDefaults*userDefaults=[NSUserDefaults standardUserDefaults];
arrayFetchFromDefaults=[userDefaults objectForKey:@“selectedcheckmark”];
ArrProductSelectDeceCheckMark=[[NSMutableArray alloc]initWithArray:ArrayFetchFromDefault];
NSLog(@“来自默认值的数组%@”,arrayFetchFromDefaults);
如果(arrProductSelectDecelectCheckMark.count==0)
{
ArrProductSelectDecleCheckmark=[[NSMutableArray alloc]init];

对于(int j=0;j,可以在tableview数据源方法中添加逻辑

   -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSString *strCell = @"cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strCell];
        if(cell==nil)
        {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strCell];
        }

        for(NSString *string in arrProductSelectDeSelectCheckMark)
        {
           if([string isEqualToString:@"SomeString"])
              {
              cell.accessoryType = UITableViewCellAccessoryCheckmark;;
              }
              else
              {
              cell.accessoryType = UITableViewCellAccessoryNone;
              }

              //rest of code

              return cell;

              }

根据需要修改它。

您需要将所选语言与语言列表进行比较,并勾选该语言。在cellForRowAtIndexpath方法中创建单元格时,您可以检查对象是否在selectedItems数组中,并对其进行更新。无需运行单独的for循环。如何可能???@AshleyRodrigues检查我的ans(如果适用)。。