2014-11-04 95 views
0

我是新手在iOS和我知道这个问题被问了很多次,但我没有得到solution.i使用tableview的应用程序在这里是我的tableview代码包含两个部分,我想用JSON Data.i填充此部分做了两个CustomCell。它很好地显示,但我无法填充我的JSON解析数据。如何设置数组数据在iOS中tableview第一部分的第一个值和tableview的第二个部分的剩余数组数据值?

我的代码是。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
if (indexPath.section == 0) 
{ 
    static NSString *[email protected]"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; 
} 
else 
{ 
    static NSString *[email protected]"CellTwo"; 
    TableCell *cellTwo=[tableView dequeueReusableCellWithIdentifier:CellIdentifierTwo]; 
    if (cellTwo == nil) 
    { 
     NSArray *nibTwo=[[NSBundle mainBundle]loadNibNamed:@"TableCell" owner:self options:nil]; 
     cellTwo=[nibTwo objectAtIndex:0]; 
     cellTwo.userInteractionEnabled=NO; 
    } 
    return cellTwo; 
} 
return nil; 
} 

这里泰伯维部分是两个,也为numberofRow代码

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
if (section == 0) 
{ 
    return 1; 
    NSLog(@"Images %@",self.imageArray); 
} 
else 
{ 
    return self.imageArray.count - 1; 
} 
} 

在没有任何数据则显示,因为我想,但我不能够填补我的数据,请您提供我任何解决方案。

+0

您可能不会尝试将您的数据应用到第1部分中的单元格。 – rmaddy 2014-11-04 06:19:00

+0

@rmaddy没有尝试应用的方法吗? – 2014-11-04 06:20:15

+0

您没有任何代码可以使用该部分中特定行的数据更新'cellTwo'。你不使用你的'imageArray'。 – rmaddy 2014-11-04 06:22:20

回答

1

@AshishGabani

看看下面的代码,我了解你的需求

我已经采取了一个数组,包含这样

的NSMutableArray值* imageArray = [[NSMutableArray的页头] initWithObjects :@ “1”,@ “2”,@ “3”,零]。

下的TableView方法:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if (section==0) return 1; 
    return imageArray.count-1; 

} 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 

    return 2; 

} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

    static NSString *simpleTableIdentifier = @"Simple"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; 
    } 
    if(indexPath.section==0) { 
     cell.textLabel.text = [imageArray objectAtIndex:indexPath.row]; 

    } else { 
     cell.textLabel.text = [imageArray objectAtIndex:indexPath.row+1]; 

    } 
    return cell; 

} 

只是评论你现有的代码和复制这些代码,粘贴您的Xcode的ViewController和运行模拟器,我觉得我达到了你的要求。

相关问题