0

enter image description hereAs i want to transfer different page when clicked on rows of different section.

   @interface TableView ()<UITableViewDelegate, UITableViewDataSource>
{
    NSArray *tableData;
    NSArray *imagesArray;
}
@end

@implementation TableView

- (void)viewDidLoad {
    [super viewDidLoad];
    tableData=[NSArray alloc];
    tableData=@[@"Delhi",@"NewYork",@"London",@"Paris",@"Munich",@"Germany",@"Delhi",@"NewYork",@"London",@"Paris",@"Munich",@"Germany",@"Delhi",@"NewYork",@"London",@"Paris",@"Munich",@"Germany"];
    imagesArray = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"delhi.jpg"],
                   [UIImage imageNamed:@"newyork.jpg"],
                   [UIImage imageNamed:@"london.jpg"],
                   [UIImage imageNamed:@"paris.jpg"],
                   [UIImage imageNamed:@"munich.jpg"],
                   [UIImage imageNamed:@"germany.jpg"],
                   [UIImage imageNamed:@"delhi.jpg"],
                   [UIImage imageNamed:@"newyork.jpg"],
                   [UIImage imageNamed:@"london.jpg"],
                   [UIImage imageNamed:@"paris.jpg"],
                   [UIImage imageNamed:@"munich.jpg"],
                   [UIImage imageNamed:@"germany.jpg"],
                   [UIImage imageNamed:@"delhi.jpg"],
                   [UIImage imageNamed:@"newyork.jpg"],
                   [UIImage imageNamed:@"london.jpg"],
                   [UIImage imageNamed:@"paris.jpg"],
                   [UIImage imageNamed:@"munich.jpg"],
                   [UIImage imageNamed:@"germany.jpg"],

                                      nil];


    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(section==0)
    {
        return 1;
    }
    else if(section==1)
    {
        return 1;
    }
    else
    {
        return 1;
    }


    //return [tableData count]/2;
    return 0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *stringt=@"SimpleTableItems";
    NSString *str;
    UIImage *image;
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:stringt ];
    if(cell==nil)
    {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:stringt];

    }

    else if (indexPath.section==0)
    {
        str=[tableData objectAtIndex:indexPath.row];
        //cell.textLabel.text=[tableData objectAtIndex:indexPath.row];
        //cell.imageView.image = [imagesArray objectAtIndex:indexPath.row];
        image=[imagesArray objectAtIndex:indexPath.row];
        [cell.imageView setImage:image ];
        [cell.textLabel setText:str];

       // cell.imageView.image=[UIImage imageNamed:@"test.jpg"];
    }
    else if (indexPath.section==1)
    {
        str=[tableData objectAtIndex:indexPath.row];
       image=[imagesArray objectAtIndex:indexPath.row];
        //cell.imageView.image = [imagesArray objectAtIndex:indexPath.row];
        [cell.imageView setImage:image ];
        [cell.textLabel setText:str ];

    }
    else if (indexPath.section==2)
    {
        str=[tableData objectAtIndex:indexPath.row];
        image=[imagesArray objectAtIndex:indexPath.row];
        [cell.imageView setImage:image ];
        [cell.textLabel setText:str];
    }


    //cell.imageView.image=[UIImage imageNamed:@"test.jpg"];
    //[cell.textLabel setText:str];
    return cell;

}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSString *header;
    if(section==0)

    {
        header=@"Section 1 Header";
    }
    else if(section==1){
        header=@"Section 2 Header";
    }
    else
    {
        header=@"3 header";
    }
    return header;
}
-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
    NSString *footer;
    if(section==0)
    {
        footer=@"Section 1 footer";

    }
    else  if(section==1)
    {
        footer=@"Section 2 Footer";
    }
    else
    {
        footer=@"Section 3 Footer";
    }
    return footer;
}

#pragma mark - TableView delegate

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES ];
    UITableViewCell *tableCell=[tableView cellForRowAtIndexPath:indexPath];
    NSLog(@"Section %d rows %d selected and it's data is %@",indexPath.section,indexPath.row,tableCell.textLabel.text);

}

firstly in tableView cell of section 2 and section 3 is not displayed but it only creates space when i click on that rows it specify you have selected this.

Narendra Pandey
  • 377
  • 9
  • 28

1 Answers1

0

Firstly it is

-(void)tableView:(UITableView *)tableView didselectRowAtIndexPath:(NSIndexPath *)indexPath

not diddeselect and on didselect u should navigate to the another view where you want to see the detailed view,like

DetailViewController *detailVC=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"detailVC"];

[self.navigationController pushViewController:detailVC animated:YES];

and then from here only u need to pass the values which u want on next view,like

detailVC.name=[tableData objectAtIndex:indexPath.row];

in detailVC create a string named name,now this name will contain the value of index path

iosDev_1205
  • 778
  • 1
  • 9
  • 23