-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [arrTemptemp count] ;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(!cell)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
for( int i =0; i<2 ; i++)
{
// arrTemp = [[arrForum objectAtIndex:i] objectForKey:@"title"];
// str1=[[arrForum objectAtIndex:i] objectForKey:@"title"];
arrTemptemp = [[arrForum objectAtIndex:i] objectForKey:@"title"];
NSLog(@"wwww:%@",arrTemptemp);
}
NSEnumerator *enumerator = [arrTemptemp objectEnumerator];
NSDictionary *item = (NSDictionary*)[enumerator nextObject];
NSLog(@"sheetal:%@",item);
cell.textLabel.text = [NSString stringWithFormat:@"%@",item];
return cell;
}
最佳答案
第一次改变
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2 ;
}
如果您想在 UITableView
上显示任意两个值,那么
这里证明了适用于 cellForRowAtIndexPath
的简单逻辑。
if(indexPath.row == 0)
{
cell.textLabel.text = [[arrForum objectAtIndex:0] objectForKey:@"title"];
// your can get whatever value from arrForum (YourArray) by change objectAtIndex
}
if(indexPath.row == 1)
{
cell.textLabel.text = [[arrForum objectAtIndex:1] objectForKey:@"title"];
// your can get whatever value from arrForum (YourArray) by change objectAtIndex
}
注意:我知道 cell.textLabel.text = [[arrForum objectAtIndex:indexPath.row] objectForKey:@"title"];
就足够了,但它只得到数组的前两个值。所以我应用上面的逻辑,OP可以得到他想要的任意两个值。
关于iphone - 我正在从服务器获取很多名称,但我只想在 UITableView 中显示 2 个名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15086969/