As 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.