如何在UITableview第一节中显示字典数组First Value,在UITableview第二节中显示Remain



我是iOS开发的新手,我使用JSON数据数组来显示表视图单元格数据,我为不同的部分制作不同的单元格,它正在工作,但现在我希望在我的第一部分中只有数据数组的第一个值,在第二部分中所有剩余的值都显示如何可能?

我为我的第一个细胞写了一个代码,但它不起作用

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0)
{
    static NSString *CellIdentifierOne=@"CellOne";
    CustumCell *cellOne =[tableView dequeueReusableCellWithIdentifier:CellIdentifierOne];
    if (cellOne == nil)
    {
        NSArray *nibOne=[[NSBundle mainBundle]loadNibNamed:@"CustumCell" owner:self options:nil];
        cellOne=[nibOne objectAtIndex:0];
        cellOne.userInteractionEnabled=NO;
    }
    {
        [cellOne.spinner startAnimating];
        NSDictionary *dict = [self.imageArray objectAtIndex:indexPath.section];
        NSString *img2=[dict valueForKey:@"front_image"];
        [cellOne.storeImage sd_setImageWithURL:[NSURL URLWithString:[img2 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[UIImage imageNamed:@"Setting.png"] options:SDWebImageHighPriority completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL)
         {
             [cellOne.spinner stopAnimating];
             cellOne.spinner.hidesWhenStopped=YES;
         }];
    }
    return cellOne;
}
}

它显示行出现错误

 NSDictionary *dict = [self.imageArray objectAtIndex:indexPath.section];

这里的imagearray是一个JSON解析数组。我知道它被问了很多次,但我没有得到解决方案。如果可能的话,请给我解决方案。

Ashish Gabani这里你的第一节只包含一行,而不是定义两个类似于的数组

NSArray *firstArray=[[NSArray alloc]init];
NSArray *secondArrayarray=[[NSArray alloc]init];

然后像一样写

self.firstArray=[self.imageArray objectAtIndex:0];
self.secondArray=[NSMutableArray arrayWithArray:self.imageArray];
[self.secondArray removeObjectAtIndex:0];

对于First Section加载第一阵列数据,对于Second Section加载第二阵列数据

希望它能帮助你。

最新更新