Download - Custom cell in objective c
![Page 1: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/1.jpg)
Objective C
HOW TO CREATE CUSTOM CELL IN IPHONE.
![Page 2: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/2.jpg)
Open your Xcode and Create a new empty project
![Page 3: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/3.jpg)
Create a new class using right click on AppDelegate.m file
![Page 4: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/4.jpg)
![Page 5: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/5.jpg)
![Page 6: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/6.jpg)
Load your first class into AppDelegate.m file.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. // Make object of that class and load nib file. UserNameListViewController *userNameListViewController = [[UserNameListViewController alloc]initWithNibName:@"UserNameListViewController" bundle:nil]; self.window.backgroundColor = [UIColor whiteColor]; self.window.rootViewController=userNameListViewController; [self.window makeKeyAndVisible]; return YES;}
![Page 7: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/7.jpg)
Adopt UITableViewDataSource Protocol in UserNameListViewController.m file
@interface UserNameListViewController ()<UITableViewDataSource/*Adopt tableViewDataSource Protocol */>{ } @end
![Page 8: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/8.jpg)
Create an array for load data into TableView.
@interface UserNameListViewController ()<UITableViewDataSource/*Adopt tableViewDataSource Protocol */>{ NSArray *userNameArray; // Create an array for load data into tableView;}@end
![Page 9: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/9.jpg)
Declare a function into UserNameListViewController.m
- (void)classInitialization;
![Page 10: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/10.jpg)
Call classInitialization from ViewDidLoad function.
- (void)viewDidLoad{ [super viewDidLoad]; [self classInitialization]; // Call from view did load for class Initialization. // Do any additional setup after loading the view from its nib.}
![Page 11: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/11.jpg)
Implement classInitialization function.
#pragma mark - Methods Implementaion. - (void)classInitialization{// Initialization array with user names. userNameArray = [[NSArray alloc]initWithObjects:@"Vishal Verma",@"Ankit",@"Parag",@"kalpak", nil];}
![Page 12: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/12.jpg)
Now create a new cell file
![Page 13: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/13.jpg)
Make a label object in NameListCell.h file for display user’s name on custom cell;
#import <UIKit/UIKit.h> @interface NameListCell : UITableViewCell{ IBOutlet UILabel *userNameLabel;}@property(nonatomic,retain)IBOutlet UILabel *userNameLabel;@end
![Page 14: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/14.jpg)
Synthesize in NameListCell.m file.
• @synthesize userNameLabel;
![Page 15: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/15.jpg)
Create xib file for custom cell.
![Page 16: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/16.jpg)
![Page 17: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/17.jpg)
![Page 18: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/18.jpg)
![Page 19: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/19.jpg)
Make connection on NameListCell.xib
![Page 20: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/20.jpg)
![Page 21: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/21.jpg)
Add TableView on UserNameListViewController.xib
![Page 22: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/22.jpg)
Implement TableView Datasource Methods into
#pragma mark - TableView Datasource Methods. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return userNameArray.count;} - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifier = @"cellIdentifier"; // Make Object Of Custom Class. NameListCell *nameListCell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if(!nameListCell){ // Load Nib File Into Array. NSArray *loadCellArray = [[NSBundle mainBundle]loadNibNamed:@"NameListCell" owner:self options:nil]; nameListCell = [loadCellArray objectAtIndex:0]; } nameListCell.userNameLabel.text = [userNameArray objectAtIndex:[indexPath row]]; return nameListCell;}
![Page 23: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/23.jpg)
Now save and Run.
![Page 24: Custom cell in objective c](https://reader036.vdocument.in/reader036/viewer/2022062617/54b75f7b4a7959a23c8b4615/html5/thumbnails/24.jpg)
Thank You For Reading My Blog.