Reputation: 3353
I'm new to iOS programming and I'm learning to use storyboard to design the UI.
I haven't wrote any code yet because all things done by now is in the storyboard.
The program is a Tabbed Application
and I replaced the first view by a UITableView
and segued it to the initial view controller.
The whole structure is like:
But when I run it in the simulator, the table view showed without any content(I have several table view cells, as you can see in the first picture).
I can't figured out what's wrong?
Upvotes: 2
Views: 899
Reputation: 6484
Unless you write some code, it would be hard to see those cells
First of all, drag an outlet from tableView to respective viewController and name it tableView.
To do that, select your custom TableViewClass in your storyboard, this will allow you to drag your outlet to that class file
then:
class TableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {...}
conform to these two protocols by implementing both
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
and
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
Also don't forget to add
self.tableView.dataSource = self;
self.tableView.delegate = self;
inside your
ViewDidLoad() method
Upvotes: 1
Reputation: 427
Select tableview in storyboard and Add like this delegate method.
Option A:
//.h file
@interface Tableviewcontroller : UIViewController< UITableViewDataSource, UITableViewDelegate>
//.M file
- (void)viewDidLoad
{
yourtablename.delegate = self;
yourtablename.datasource = self;
}
Option B:
Upvotes: 1
Reputation:
please add datasource and delegate to self in ViewDidLoad
or through storyboard it works for you
- (void)viewDidLoad
{
yourtablename.delegate = self;
yourtablename.datasource = self;
}
Upvotes: 0