---
title: "How to populate uitableviewby programmatically?"  
description: "How to populate uitableviewby programmatically?"  
author: "Anonymous User"  
published: 2014-10-17  
updated: 2014-10-17  
canonical: https://www.mindstick.com/forum/2411/how-to-populate-uitableviewby-programmatically  
category: "iphone"  
tags: ["iphone", "ios", "ios 7"]  
reading_time: 2 minutes  

---

# How to populate uitableviewby programmatically?

I am creating a [custom](https://www.mindstick.com/blog/12298/use-custom-writing-services-to-get-through-the-finals) [drop down](https://www.mindstick.com/forum/263/drop-down-list-problem) menu.On [button click](https://www.mindstick.com/forum/790/form-gets-submiited-twice-on-button-click) i am unhiding the UIView which is subview of my root view. Inside that subview i have added UItableview programmatically.Till this my code is [working fine](https://answers.mindstick.com/qa/95550/why-is-the-safari-browser-not-working-fine),but i am stuck while populating the table with my data array.so can anybody help me to [solve this problem](https://answers.mindstick.com/qa/94681/my-google-assistant-shows-completely-different-search-results-from-what-i-ask-how-can-i-solve-this-problem)..... thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)

I have assigned the UItableView [delegate](https://www.mindstick.com/articles/777/delegate-and-event-in-c-sharp) and [datasource](https://www.mindstick.com/blog/447/listing-the-databases-connected-to-the-datasource) also..

**Here is my [implementation](https://www.mindstick.com/forum/33764/how-to-implementation-of-class-in-c-sharp)**

```
- (void)viewDidLoad{[super viewDidLoad];self.grades = [[NSArray alloc]initWithObjects:@"Excellent",@"Good",@"ok",@"Not Good", nil];self.tableView.delegate = self;self.tableView.dataSource = self;self.coverView = [[UIView alloc]init];self.shadowView = [[UIView alloc]init];self.coverView = [[UIView alloc] initWithFrame:CGRectMake(90.0f, 220.0f, 150.0f, 200.0f)];self.coverView.backgroundColor = [UIColor whiteColor];CALayer * layer = self.coverView.layer;layer.shadowOffset = CGSizeMake(1, 1);layer.shadowColor = [[UIColor blackColor] CGColor];layer.shadowRadius = 4.0f;layer.shadowOpacity = 0.80f;layer.shadowPath = [[UIBezierPath bezierPathWithRect:layer.bounds] CGPath];[[self view] addSubview:self.coverView];self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 140.0f, 200.0f)];[self.coverView addSubview:self.tableView];self.coverView.hidden = YES;[self.tableView reloadData];}- (IBAction)buttonClicked:(id)sender{CGRect screenRect = [[UIScreen mainScreen] bounds];self.shadowView = [[UIView alloc] initWithFrame:screenRect];self.shadowView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2];[self.view addSubview:self.shadowView];[[self view] addSubview:self.coverView];self.coverView.hidden = NO;[self fadeIn];[self.tableView reloadData];}- (IBAction)screenTapped:(id)sender{NSLog(@"Screen Tapped");[self fadeOut];self.shadowView.hidden = YES;[self.shadowView removeFromSuperview];}- (void)fadeIn{self.coverView.transform = CGAffineTransformMakeScale(0.5, 0.5);self.coverView.alpha = 0;[UIView animateWithDuration:.35 animations:^{    self.coverView.alpha = 1;    self.coverView.transform = CGAffineTransformMakeScale(1.4,1.4);}];}- (void)fadeOut{[UIView animateWithDuration:.35 animations:^{    self.coverView.transform = CGAffineTransformMakeScale(1.3, 1.3);    self.coverView.alpha = 0.0;} completion:^(BOOL finished){    if (finished)    {        [self.coverView removeFromSuperview];    }}];}- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{return 1;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{return [self.grades count];}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{NSString * cellIdentifier = @"Cell";UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];if (cell == nil){    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];}cell.textLabel.text = [self.grades objectAtIndex:indexPath.row];return cell;}
```

ios objective-c iphone uitableview

## Replies

### Reply by Anonymous User

looks like you need to set delegates after [UITableView alloc].\
self.tableView = [[UITableView alloc]self.tableView.delegate = self;self.tableView.dataSource = self;


---

Original Source: https://www.mindstick.com/forum/2411/how-to-populate-uitableviewby-programmatically

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
