About
Home > Tutorials Home > Ios > UITalbeview GroupStyle in iOS

UITalbeview GroupStyle in iOS

Published on October 17, 2019 8:19:24 PM

Button Example

We are an online tutoring company that has laid its foundation in utilizing Multiple Intelligence methodology to understand specific needs and learning styles of a student.UITableView makes sense to group information and show it to the user.So that we patch a particular student to a tutor having a compatible teaching style. We have devised a smart online tutoring system to give you measurable results.Schools, cramped with students, fail to give your child the edge, the motivation and the right teacher guidance to help him find the true potential. We at Eonlinetutors.com make sure that your child gets the perfect learning environment to outperform.




Step 1 : Open the XCode and create a new Single View Based Application template. Give the application name "UITableViewGroup Example". Copy this Code to the ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,retain) NSArray *myCountries;

@end

Step 2 : Copy the Following Code into your ViewController.m File.

#import "ViewController.h"

@implementation ViewController

@synthesize  myCountries;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath
{
	if (indexPath.section == 0) 
	{
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"First Section" message:[myCountries objectAtIndex:indexPath.row] delegate:nil cancelButtonTitle:@"Okey" otherButtonTitles:nil, nil];
		[alert show];
	}
    else if(indexPath.section == 1)
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Second Section" message:[myCountries objectAtIndex:indexPath.row] delegate:nil cancelButtonTitle:@"Okey" otherButtonTitles:nil, nil];
		[alert show];
	}
    else
	{
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Third Section" message:[myCountries objectAtIndex:indexPath.row] delegate:nil cancelButtonTitle:@"Okey" otherButtonTitles:nil, nil];
		[alert show];
	}
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 0) 
	{
        return @"First Section";
    }
    else if(section == 1)
    {
        return @"Second Section";
	}
    else
        return @"Third Section";
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [myCountries count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
	if(cell == nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
	}
    cell.textLabel.text = [myCountries objectAtIndex: indexPath.row];
	cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
	return cell;
}

- (void)viewDidLoad
{
    myCountries = [[NSArray alloc]initWithObjects:@"India",@"Australia", @"USA",@"UK",@"Canada", @"Srilanka",@"England",@"America",@"Itely", @"Spain",@"Germeny",@"Japan",@"Brazil",@"SwitzerLand", @"Hongkong",@"China",nil, nil];
	[super viewDidLoad];
}

@end
ALL COMMENTS (2)
Abhishek Bedre 2017-03-28 17:25:15
I have implemented my own "jarvis"....thanks to this example.        
2019-01-03 13:22:19
It is working fine in desktop but not working in android mobile