2) Right click on table controller have a new file, iOS source cocoa touch class
8) Go to controller.m and go to method "CellForRowAtIndexPath" and remove the code of default cell, implement custom cell by following
- (void)viewDidLoad {
idevices=[NSArray arrayWithObjects:@"iPhone",@"iPad",@"iPod",@"iPadmini", nil];
androidDevices=[NSArray arrayWithObjects:@"HTC",@"samsung",@"Lenevo",@"Nexus", nil];
idevicesImg=[NSArray arrayWithObjects:@"1.jpeg",@"2.jpeg",@"3.jpeg",@"4.jpeg", nil];
andImg=[NSArray arrayWithObjects:@"11.png",@"22.png",@"33.jpeg",@"44.jpeg", nil];
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//return 5;
if (section==0) {
return idevices.count;
}
else
{
return androidDevices.count;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell" forIndexPath:indexPath];
// // Configure the cell...
// // cell.textLabel.text=@"Hello iOS SDK";
// if (indexPath.section==0) {
// cell.textLabel.text=[idevices objectAtIndex:indexPath.row];
// }
// else
// {
// cell.textLabel.text=[androidDevices objectAtIndex:indexPath.row];
// }
static NSString *simpleTableIdentifier = @"MyCellID";
MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
// Configure Properties
if (indexPath.section==0) {
cell.prdName.text=[idevices objectAtIndex:indexPath.row];
cell.prdPrice.text=@"20000";
cell.prdDes.text=@"This is an apple device";
cell.prdImage.image=[UIImage imageNamed:[idevicesImg objectAtIndex:indexPath.row]];
}
else{
cell.prdName.text=[androidDevices objectAtIndex:indexPath.row];
cell.prdPrice.text=@"10000";
cell.prdDes.text=@"This is an Android device";
// NSLog(@"height is %f", cell.prdImage.frame.size.width);
// cell.prdImage.frame.size.width== cell.prdImage.frame.size.width-30;
// NSLog(@"height is %f", cell.prdImage.frame.size.width);
//
cell.prdImage.image=[UIImage imageNamed:[andImg objectAtIndex:indexPath.row]];
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 115.0;
}