Skip to content

Simple example of how to populate data to a UITableView (iOS programming with Objective-C)

License

Notifications You must be signed in to change notification settings

ngthanhbinh85/Populating-the-UITableView-iOS-Objective-C

Repository files navigation

Populating the UITableView iOS Objective-C

Simple example of how to populate data to an UITableView (iOS programming with Objective-C)

In this example, the data is stored in an Array of Student objects.

Call this to get the Data:

+(NSMutableArray *)getStudentList;

To populate data to UITableView, we need to implement the UITableViewDataSource protocol.

@interface ViewController () <UITableViewDataSource> {
    NSMutableArray *myData;
    __weak IBOutlet UITableView *myTableView;
}

@end

myData points to the array of Student objects.

Then, the ViewController will be the data source:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    myData = MyData.getStudentList;
    
    myTableView.dataSource = self;
    
}

Finally, implement the following 2 methods:

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath;
- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

About

Simple example of how to populate data to a UITableView (iOS programming with Objective-C)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published