Reputation: 2450
In my current app I have 24 different views, each view has it's own ViewController
. As the time has passed I have come to the realization that changing them to a TableViewController
would not only function better, it would also in fact look better.
Typically the way that I have been assigning the custom classes to my views has been to go in Xcode to: File > New > File > Objective-C Class.
I make the class and make sure that it is a subclass of UIViewController
. After the file has been created I click on my View Controller in the Storyboard file, go to the inspector and set the custom class to be myNewViewController
, all done!
But this is not the case when working with a UITableView
, I was able to add a table view in the storyboard file, customize it / add the sections / cells, etc, but when I would like to assign a new class that I have created following the steps mentioned above, except this time I subclass from UITableViewController
I get the following warning:
With this being the incomplete code:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
return cell;
}
Additionally, the view shows up blank in when ran on my iOS device.
I am aware that this implementation must be completed before it can properly run, but is there a specific way of this that it would link the view that I was working with and it's ViewController? This way none of this configuration is needed?
What is my next step to follow?
Thanks for the & advice!
Edit I have also attempted to set the cell identifier to "Cell", and also tried changing the values so that numberOfSections returns 5, and numberOfRowsInSection returns 2 but still no luck, app crashed and I get this in the debug log:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
***
Upvotes: 1
Views: 982
Reputation: 6918
You are using static cells. You shouldn't use the data source methods.
Upvotes: 1