Customize Table View

Hello, now we are starting 'Customize Table view it's huge of use is take in our projects so its very important to learn.So, you can see bellow demo. I hope it's very helpful.

Here  see customize table view in video for some idea how was customize table view.





Step 1- Now first of we creating simple table view that we are learned early. If you can't so don't worry Click here for learning. If you can't understand basic so you can't will be learning 'Customize Table View'.

Now we are creating ‘Customise Table View’ that’s for you can see forward.

Step 2-Now go into ‘Main.storyboard’ and click on ViewController then give process same as given into bellow picture.





Click ViewController-> Editor-> Embed In-> Navigation Controller. 

Step 3- Now we are pass data from ‘ViewController’ to ‘NewViewController’.Here we are take also one ViewController from ‘Object Library’ and drag into ‘Main.storyboard’.


Step 4-Now create ‘class’ for this click on above bar into 
File ->New ->File…
Now give class name ’MyCell’ and select subclass ‘UITableViewCell’ and create.Here we are using this class for tableview cell.





Step 5- Now create one more class same as create above but here give class name ’NewViewController’ and select subclass ‘UIViewController’



Now give class name of our controller.
Click on Our new controller ->identity Inspector ->Class.Write  here ’NewViewController’. 

Step 6-Now select our cell and drag by right click same as given bellow type. Here give segue ->push.

Step 7-Now were click on connection between ‘ViewController’ and ’NewViewController’ and give identifier ‘send’ into ‘Attribute Inspector’. 

Step 8-Now open ’NewViewController.h’  and write property.
#import <UIKit/UIKit.h>
#import "MyCell.h"
#import "ViewController.h"
@interface NewViewController : UIViewController{
    
    IBOutlet UILabel *numberLabel;
}
@property (strong,nonatomic) NSString *number;

@end


Step 9-Now write into ‘ViewController.m’ segue method.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    
    if ([segue.identifier isEqualToString:@"send"]) {
        NSIndexPath *indexPath = [tblView indexPathForSelectedRow];
        NewViewController *destViewController = segue.destinationViewController;
        
        destViewController.number = [arrayNumber objectAtIndex:indexPath.row];
        
    }
}

Step 10-After that write code in ’NewViewController.m’ into [super viewDidload] .

 numberLabel.text = number;
 NSLog(@"%@",number);

Step 11-Here bellow give all project code.

1.ViewController.h

#import <UIKit/UIKit.h>
#import "MyCell.h"
#import "NewViewController.h"

@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
{
    
    IBOutlet UITableView *tblView;
    NSMutableArray *arrayNumber;
}
@end

2.ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    arrayNumber = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10", nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark- TableView Delegate method
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"cell";
    
    MyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.text = [arrayNumber objectAtIndex:indexPath.row];
    cell.detailTextLabel.text = @"More text";
    
    cell.accessoryTypeUITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    NSLog(@"Section:%ld Row:%ld selected and its data is %@",
          (long)indexPath.section,(long)indexPath.row,cell.textLabel.text);
    
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    
    if ([segue.identifier isEqualToString:@"send"]) {
        NSIndexPath *indexPath = [tblView indexPathForSelectedRow];
        NewViewController *destViewController = segue.destinationViewController;
        
        destViewController.number = [arrayNumber objectAtIndex:indexPath.row];
        
    }
}


@end

3.NewViewController.h

#import <UIKit/UIKit.h>
#import "MyCell.h"
#import "ViewController.h"
@interface NewViewController : UIViewController{
    
    IBOutlet UILabel *numberLabel;
}
@property (strong,nonatomic) NSString *number;

@end

3.NewViewController.m
#import "NewViewController.h"

@interface NewViewController ()

@end

@implementation NewViewController
@synthesize number;
- (void)viewDidLoad {
    [super viewDidLoad];
    
    numberLabel.text = number;
    NSLog(@"%@",number);
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end


Step 12-Now press RUN and you can see bellow type simulator 


Step 13- Now click anyone cell then you can see bellow type window.




Here you can make some relaxation.Click here.

Comments

Popular posts from this blog

Dera Sacha Sauda chief Gurmeet Ram Rahim Singh - News Upword