Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.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
Objective c 如何使用NSMUTABLEARRY在UItableView中显示NSSet值_Objective C_Ios_Xcode_Uitableview_Nsset - Fatal编程技术网

Objective c 如何使用NSMUTABLEARRY在UItableView中显示NSSet值

Objective c 如何使用NSMUTABLEARRY在UItableView中显示NSSet值,objective-c,ios,xcode,uitableview,nsset,Objective C,Ios,Xcode,Uitableview,Nsset,我有一个这样的元素数组 150,, 150, 150, 571, 571, 571, 692, 692, 692, 123, 123, 123, 144, 144, 144, 147, 147, 147, 155, 155, 155, 542, 542, 542, 548, 548, 548, 551, 551, 551 我曾经在tableviewcell中显示我的数组元素,在这里我使用了如下代码 NSArray *array=[jsonarray valueForKey:@"ID"]; myS

我有一个这样的元素数组

150,, 150, 150, 571, 571, 571, 692, 692, 692, 123, 123, 123, 144, 144, 144, 147, 147, 147, 155, 155, 155, 542, 542, 542, 548, 548, 548, 551, 551, 551

我曾经在tableviewcell中显示我的数组元素,在这里我使用了如下代码

NSArray *array=[jsonarray valueForKey:@"ID"];
mySet = [NSSet setWithArray:array] ;

NSLog(@"%@",mySet);
现在我得到了我的所有元素,在myset中没有重复为11个元素,但如果我打印myset值,我得到的结果如下

NSArray *array=[jsonarray valueForKey:@"ID"];
mySet = [NSSet setWithArray:array] ;

NSLog(@"%@",mySet);
2012-08-01 12:49:53.049佐提研发[3647:f803]{( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )} 2012-08-01 12:49:53.050佐提研发[3647:f803]{( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )} 2012-08-01 12:49:53.050佐提研发[3647:f803]{( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )} 2012-08-01 12:49:53.051佐提研发[3647:f803]{( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )} 2012-08-01 12:49:53.051佐提研发[3647:f803]{( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )} 2012-08-01 12:49:53.052佐提研发[3647:f803]{( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )} 2012-08-01 12:49:53.052佐提研发[3647:f803]{( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )} 2012-08-01 12:49:53.053佐提研发[3647:f803]{( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )} 2012-08-01 12:49:53.053佐提研发[3647:f803]{( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )} 2012-08-01 12:49:53.054佐提研发[3647:f803]{( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )} 2012-08-01 12:49:53.054佐提研发[3647:f803]{( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )}

如果我试图在UItableviewcell中打印它,我在返回[myset count]时遇到了错误的访问问题;。“我的表视图”单元格包含

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return  [myset count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


{        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];



}
// Configure the cell...

cell.textLabel.text=[myset objectAtIndex:indexPath.row];    

return cell;
}

这里jsonarray是NSMutableArray,myset是NSSet..Guidance please..

原因是NSSet不接受重复项,因此您的NSMutableArray中有更多元素

因此,您必须选择在所有数据源方法中使用其中一种方法