简体   繁体   中英

UITableView Cell Titles Don't Populate

So basically I have a problem, i have never used storyboard before and it's completely frustrating me but i'm trying to learn it. I have multiple navigation controllers where i embedded all of them in a single tab bar controller. (See Pic 1)![Pic 1][1]

However, I can't get any type of data to populate for the cell.textLabel.text

I'm sure it's an easy fix, but like I said I'm new to storyboards.

My code is below, but first here is what i have set in storyboard:

TabBarController is set to Initial View Controller. Class is set to default. All Sizes are set to inferred. Triggered Segues are set to all 4 Navigation Controllers

For my Publications Navigation controller (The first one i'm trying to get to populate data) I have the class set to default. Triggered Segues are set to root view controller which in this case is title root view controller Presenting Segues as a relationship from tab bar controller

The Root View Controller of that Navigation controller i have the class set to "PublicationsTableViewController" Table View Content is set to Dynamic Prototypes Outlets: dataSource is Root view Controller (the one it's in) delegate is Root View Controller (the one it's in)

Table View Cell has no outlets or segues yet Style is custom Reuse Identifier is "Cell"

In PublicationsTableViewController my code is:

.h

@interface PublicationsTableViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) NSArray *mainpubArray

.m

@interface PublicationsTableViewController ()

@end

@implementation PublicationsTableViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"PUBLICATIONS";

_mainpubArray = @[@"Animals", @"Buildings", @"Vehicles", @"Entertainment"];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return [_mainpubArray count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

 static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

cell.textLabel.text = [_mainpubArray objectAtIndex:indexPath.row];

return cell;
}

![enter image description here][2]

Any help would be appreciated.

You are returning 0 as the number of sections...

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 0;
}

Should be...

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;  //Or how many sections you need
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM