0

i am newbie in iOS development. my array contain 50 values i want to show this 50 values in one by one in 50 section then i write a code for that like as

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
 {
return self.dataArray.count;
 }
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}

then i got 50 section but all section contain same array value i want to show that each section contain one by one data.Please give me any solution if it was possible

My TablwviewCell:Rowatindexpath method

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellidentifier=@"Cell";
CustumCell *cell=[tableView dequeueReusableCellWithIdentifier:cellidentifier];
if (cell == nil)
{
    NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"CustumCell" owner:self options:nil];
    cell=[nib objectAtIndex:0];
}

NSDictionary *dict = [self.imagesa objectAtIndex:indexPath.item];
NSString *img2=[dict valueForKey:@"post_image"];

[cell.photoimage sd_setImageWithURL:[NSURL URLWithString:[img2 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[UIImage imageNamed:@"Hisoka.jpg"] options:SDWebImageProgressiveDownload completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    dispatch_async(dispatch_get_main_queue(), ^{
        NSLog(@"downloaded");

    });
}];
NSString *name=[dict valueForKey:@"post_title"];
cell.namelabel.text=name;
NSString *des=[dict valueForKey:@"post_content"];
cell.deslabel.text=des;


NSDateFormatter * dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
 NSString *date=[dict valueForKey:@"post_date"];
NSDate * dateNotFormatted = [dateFormatter dateFromString:date];
[dateFormatter setDateFormat:@"d-MMM-YYYY"];
NSString * dateFormatted = [dateFormatter stringFromDate:dateNotFormatted];
NSLog(@"Date %@",dateFormatted);
cell.datelabel.text=dateFormatted;
return cell;
}
3
  • Could you post your tableView:cellForRowAtIndexPath: method? Commented Oct 18, 2014 at 8:05
  • yes i post my tableview:cellForRowAtIndexPath method. Commented Oct 18, 2014 at 8:32
  • One issue is that when i run this application and do nothing but after 2 to 3 minutes error in line NSDictionary *dict = [self.imagesa objectAtIndex:indexPath.item]; any solution for that???? Commented Oct 18, 2014 at 9:45

3 Answers 3

2

If you think logically through this, the indexPath.row will always be 0 since each section has one row. Hence, the row number you are using on the array will grab the same item every time.

The only value that's increasing each time is the indexPath.section. If you use this value while iterating through the array it will lead to the different values in the corresponding array.

Sign up to request clarification or add additional context in comments.

Comments

1

In your cellForRowAtIndexPath method (and the other datasource/delegate methods, use indexPath.section as the index to your data array, not indexPath.row.

Or in your case, replace

NSDictionary *dict = [self.imagesa objectAtIndex:indexPath.item];

with

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

Comments

0

use indexpath.sectioninstead ofindexpath.rowin cellForRowAtIndexPath.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.