【发布时间】:2012-08-01 07:38:25
【问题描述】:
我有一个这样的元素数组
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 值,我得到了这样的结果
2012-08-01 12:49:53.049 jothi 研发[3647:f803] {( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )} 2012-08-01 12:49:53.050 jothi 研发[3647:f803] {( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )} 2012-08-01 12:49:53.050 jothi 研发[3647:f803] {( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )} 2012-08-01 12:49:53.051 jothi 研发[3647:f803] {( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )} 2012-08-01 12:49:53.051 jothi 研发[3647:f803] {( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )} 2012-08-01 12:49:53.052 jothi 研发[3647:f803] {( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )} 2012-08-01 12:49:53.052 jothi 研发[3647:f803] {( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )} 2012-08-01 12:49:53.053 jothi 研发[3647:f803] {( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )} 2012-08-01 12:49:53.053 jothi 研发[3647:f803] {( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )} 2012-08-01 12:49:53.054 jothi 研发[3647:f803] {( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )} 2012-08-01 12:49:53.054 jothi 研发[3647:f803] {( 551, 548, 692, 150, 155, 147, 542, 571, 123, 144 )}
如果我尝试在 UItableviewcell 中打印它,我会在返回时遇到 BAD ACCESS 问题[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..请指导..
【问题讨论】:
标签: objective-c ios xcode uitableview nsset