2014-11-04 92 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和運行模擬器,我覺得我達到了你的要求。

相關問題