Wednesday 8 June 2011

How to Create a GroupedStyle Table View

@interface WhatWeDoViewController : UIViewController
{
UITableView *tableview;
}
@property(nonatomic ,retain) UITableView *tableview;
@end

#import "WhatWeDoViewController.h"
@implementation WhatWeDoViewController
@synthesize tableview;

- (void)viewDidLoad
{
[super viewDidLoad];
tableview=[[UITableView alloc]initWithFrame:CGRectMake(3,125.0, self.view.bounds.size.width-5, 300.0)style:UITableViewStyleGrouped];
tableview.delegate = self;
tableview.dataSource = self;
tableview.autoresizesSubviews = YES;
tableview.backgroundColor=[UIColor clearColor];
tableview.alpha=0.7;
UIColor *separator = [[UIColor alloc] initWithRed:49.0 green:62.0 blue:0.0 alpha:1.0];
tableview.separatorColor = separator;
[self.view addSubview:tableview];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// The number of sections is based on the number of items in the data property list.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 4;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell =[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:nil ] autorelease];
cell.backgroundColor=[UIColor grayColor];
cell.alpha=0.5;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//Add label into cell
UILabel *titleLabel =[[UILabel alloc]initWithFrame:CGRectMake(10.0, 5.0, cell.contentView.bounds.size.width, 40.0)];
titleLabel.font=[UIFont fontWithName:@"Helvetica-Bold" size:18];
titleLabel.backgroundColor=[UIColor clearColor];
titleLabel.textColor=[UIColor purpleColor];
titleLabel.opaque = YES;
[cell.contentView addSubview:titleLabel];

if(indexPath.row==0)
{
titleLabel.text= @"Software Development";
}
if(indexPath.row==1)
{
titleLabel.text= @"Research & Development";
}
if(indexPath.row==2)
{
titleLabel.text= @"Industries Served";
}
if(indexPath.row==3)
{
titleLabel.text= @"Functional Offering";
}
return cell;
[titleLabel release];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
//Row selection
if(indexPath.row==0)
{
TechnologyViewController *myController=[[TechnologyViewController alloc]init];
[[self navigationController] pushViewController:myController animated:YES];
myController.title = @"Development";
}
if(indexPath.row==1)
{
ResearchViewController *myController=[[ResearchViewController alloc]init];
[[self navigationController] pushViewController:myController animated:YES];
}
if(indexPath.row==2)
{
IndustriesViewController *myController=[[IndustriesViewController alloc]init];
[[self navigationController] pushViewController:myController animated:YES];
}
if(indexPath.row==3)
{
FunctionalViewController *myController=[[FunctionalViewController alloc]init];
[[self navigationController] pushViewController:myController animated:YES];
}
}

No comments:

Post a Comment