I am trying to push a table view controller that I have on my storyboard from a view controller that I don't have in my storyboard. I get these errors when i get to initializing the first table view cell. I've made sure the table view controller and the table view cell are set to the correct class types that I've defined and I've set the correct identifier for the cell.
Error Occurs at Line:
CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"ListPrototypeCell" forIndexPath:indexPath];
Error:
*** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2935.137/UITableView.m:5439
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier ListPrototypeCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
What am I missing?
P.S that other link does not have the answer, I need to initialize multiple cells of this type, I need the index for different data.
Why not just put all the view controllers in one storyboard?
If you're trying to push from a UITableViewCell, you could use a segue method.
First: Control-Drag from your TableViewController to your ViewController to link them with a push segue. Name the segue. E.G. "segueName"
Create a prepareForSegue method like so:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"segueName"])
{
// do whatever you want here
}
and then under your didSelectRowAtIndexPath:, run the segue using this:
[self performSegueWithIdentifier:#"segueName" sender:nil];
Perhaps you could elaborate a bit more, if this does not work.
Related
I'm adding a split ViewController with the table view and detail view:
The tableview works fine the cell are been populated and everything but when one of the cells is been selected I get the error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<masterViewController: 0x15ce0e9b0>) has no segue with identifier 'detailView''
Here is my code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"detailView" sender:[_arrayOfFiles objectAtIndex:indexPath.row]];
}
Here is the info of the detailView:
I add identifier to the storyboard segue:
but now I'm getting the following error:
* Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'show tableVIew'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
* First throw call stack:
You need to set the identifier for the segue, not the viewController. If you click on the line joining the two viewControllers, you can then set the attributes for the segue in the attributes inspector:
If I'm not wrong you should be adding a Navigation Controller to bot the Master and Detail View Controllers.
Additionally, for a split controller to function it must be set as the root controller.
Good luck!
my code is breaking on the segue. the segue was modal at first , i tried to change it to push but its still not working my code is the following :
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
if ([[segue identifier ] isEqualToString:#"detailLoanSeg"]){
detailLoan *theController=[segue destinationViewController];
theController.time=_time;
theController.cuurLoan=_cuurLoan;
theController.currName=_currName;
}
}
and the error in xcode is :
014-05-07 04:38:11.257 LoanCalc[1561:a0b] -[UIViewController setTime:]:
unrecognized selector sent to instance 0xa05f1f0
2014-05-07 04:38:11.266 LoanCalc[1561:a0b] *** Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: '-[UIViewController setTime:]:
unrecognized selector sent to instance 0xa05f1f0'
It looks like, in storyboard, you forgot to indicate the custom class of the destination view controller. In storyboard, select that destination VC, click the third inspector from the right and set it's Custom Class to "detailLoan" (which violates class naming convention).
The error is that your destination vc is a generic UIViewController, which naturally doesn't implement the setTime: method.
Are you sure the destination class is your View Controller and not a UINavigationController? Put a breakpoint and check what theController class is. Also make sure that the view controller in the Storyboard has its class set from the default UIViewController to your custom subclass. It's almost certainly one of those two issues.
Let's say I have the cells for a UITableView outlined programmatically. Labels, positioning, etc... In order to drag a segue to a different view, I need to see some visual representation of a prototype cell in storyboard. How do I proceed?
What I have tried is to drag a prototype cell onto my UITableView. I changed "Identifier" to my reuse cell identifier which was set in code. After this, I proceeded to link up the prototype cell by right dragging to the destination view, selecting modal, etc... When I run the app, nothing happens after I tap on a cell.
What would the best method be to link up an entirely coded cell with a visual depiction in storyboard?
Not sure what code to paste here, or if it's even necessary since I'm asking for generic information. Please let me know if and what I should include for example.
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:#"alertDetail"]) {
NSIndexPath *indexPathA = [[self.tableViewA indexPathsForSelectedRows] lastObject];
NSString *grabTicker = [[homeJson objectAtIndex:indexPathA.row]objectForKey:#"returnId"];
[[segue destinationViewController] setGrabTicker:grabTicker];
}
}
Create the segue from the view controller itself to the destination view controller by ctrl dragging from the view controller icon below the view layout to the destination view controller.
Name the segue.
Use the segue:
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
[self performSegueWithIdentifier:#"alertDetail" sender:indexPath];
}
Then your prepareForSegue looks like:
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(NSIndexPath*)indexPath {
if([[segue identifier] isEqualToString:#"alertDetail"]) {
NSString *grabTicker = [[homeJson objectAtIndex:indexPath.row]objectForKey:#"returnId"];
[[segue destinationViewController] setGrabTicker:grabTicker];
}
}
Of course, all of this begs the question of why you're not just doing the cell layout as a prototype cell in a storyboard, but there ya go.
Change the class of the prototype cell in your storyboard to the subclass of the cell you use in code. Make sure to set the prototype cell's type to custom so that it doesn't replace your cell's view hierarchy.
(As a side note, remember to add your views to the contentView of the cell, not directly to the cell itself!)
In my storyboard I have 2 views one master and one detail with list. I want to show detail view on master. When I add detail to master like that:
- (void)viewDidLoad
{
[super viewDidLoad];
tableViewController = [[TableViewController alloc] init];
[self addChildViewController:detailVC];
[self.view addSubview:detailVC.view];
}
I get crash like that:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
Im sure that there is everything ok with my table viewController becouse when I set it to rootViewController there is everything ok. What I'm doing wrong?
Looks like its an issue with tableview delegate methods. In story board please use static cell for your table view controller and remove table view delegate methods or else implement all required table view delegate methods.
I am trying to segue from one UIViewController (VC1) to a UITableViewController (VC2) and I have tried all the usual suspects. Other posts did not seem to find a solution
In the Storyboard I created a modal segue from VC1 to VC2 and give it the identifier "VC2Segue".
Clicking VC1's connections properties shows a 'Storyboard Segue': modal--VC2.
Clicking VC2's connections properties shows a 'Referencing Story Board Segue': modal--VC1
In VC1 I have a UITableViewDelegate method that responds to cell selections in VC1. This is where I attempt to segue to the details view (VC2):
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
[self performSegueWithIdentifier:#"VC2Segue" sender:self];
}
However, as soon as performSegueWithIdentifier is called I receive an exception:
'NSInvalidArgumentException', reason: 'Receiver (VC1) has no segue with identifier 'VC2Segue''
In case it is relevant. VC1 inherits from an external proprietary library (Parse.com: PFQueryTableViewController) which appear to instantiate a `UITableView'. Hence the UITableView does not show TableCells on the Storyboard, instead VC1 is a delegate of UITableView, which which is how VC1 (A UIViewController) accesses the above method.
I've tripled checked the connections, cut and pasted the text fields, ensured that the storyboard nibs point to classes VC1 and VC2 respectively, and tired both push and modal. I'm clearly missing something, but this is my first tour of duty with iOS.