How can I use a uitableview inside of a uiviewcontroller? Below is an example of what I'm trying to do (except this is just the UITableview
in my Storyboard):
I've figured out that I need to add the delegate and data source to my header:
//MyViewController.h
@interface MyViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
In my Implementation file, I've added the required methods:
//MyViewController.m
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"cellForRowAtIndexPath");
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FileCell"];
NSLog(@"cellForRowAtIndexPath");
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *fileListAct = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:nil];
cell.textLabel.text = [NSString stringWithFormat:@"%@",[fileListAct objectAtIndex:indexPath.row]];
return cell;
}
The delegate
, datasource
, and UITableView
are all hooked up in my Storyboard:
I can't get the TableView to load the content that I tell it to. It always comes up blank. Why won't the TableView fill with the content I tell it to in the cellForRowAtIndexPath method? What am I missing here?