Exception related to accessoryActionSegueTemplate - ios

I got exception on on dequeueReusableCellWithIdentifier:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"pointcell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];// Here is exception
if( cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
...
return cell;
}
Exception:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UITableViewCell 0xca51470> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key accessoryActionSegueTemplate.'
I did set identifier to Custom type cell in Storyboard. I have set Accessory Action segue in Storyboard. I think it's related to that particular type but I don't understand what should I do prevent crash.

It seems a bit too late, but I've just faced the same problem and found a solution.
When you Control+Dragging a segue from UITableViewCell in Interface Builder it offers you to create a segue for cell or accessory view. If you create it for accessory view and run your app under iOS 5 you are in trouble since accessory segues were not supported in that version.
You can drag a segue from ViewController instead and include this code (taken from here):
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"SegueID"
sender:[tableView cellForRowAtIndexPath:indexPath]];
}

Related

App crash in IOS 7 working IOS 8

I am using Custom cell(friendListCell) in my app. when i run this into an IOS 8 and later it works but in IOS 7 it crash and show error like below. i could not find the error where it present,
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UILabel 0x17892a10> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key keyPath.'
Below the code,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath:indexPath];
return cell;
}
Note:
I delete all the reference to this cell even though it shows error.
That error message means that you are setting a variable on a UILabel from inside the storyboard/xib file that doesn't exist.
You can change the code anyway you want and that won't fix the problem. The error is in your storyboard or xib file. Are you trying to set a variable called keyPath in your storyboard/xib file?
Try this one for creating Cell:
static NSString *CellIdentifier = #"cell";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}

Unable to deque cell with identifier title

I am getting the following error when I press a button that opens a tableview:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier title - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
Here is the code in the view controller for the tableview and the method that's causing the problem:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
return cell;
}
I researched the error and I tried removing the forIndexPath:indexPath so the code looked like:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
return cell;
}
Now this caused a new error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:
now I did some logging to find out that cell == nil was true so I added a check for that as suggested by some earlier questions:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = [[UITableViewCell alloc] init]
}
return cell;
}
Now this removed all errors but now when I open the tableview, the cells are empty when I want the ones that I created in the storyboard.
How do I fix this problem?
Here is what the View Controller looks like in the storyboard:
there are two cell recycle methods you can call on a UITable
View,
-(UITableViewCell *) dequeueReusableCellWithIdentifier:forIndexPath:
-(UITableViewCell *)dequeueReusableCellWithIdentifier:
its somewhat confusing, but they are quite different in how they are used. The one which takes a second argument (of type NSIndexPath) is dependant on you first having registered a class or xib file with the tableView, in order that the tableView can create a cell ad-hoc for you when there isn't one handy for recycling. This first method will always return a cell, so you can code your cellForRowAtIndexPath: much like you have.
the second method (which takes only one argument, the (NSString *)cellIdentifier can and will return nil when there is no cell handy for recycling. So when you use this one you should test the result for nil and create a cell in that case.
eg
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellId = #"cellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId];
}
//etc etc decorate your cell...
return cell;
}
In order to exploit your cell prototypes you will need to register a class or xib for each row/section, so that the table knows which cell to create. The recycling stuff only really works once enough cells have been created to fill the screen and you start scrolling. Good luck
If you are creating your prototype cells in a Storyboard you need to set the "Identifier" field for them to your "CellIdentifier" string. You can do this by selecting the cell and looking in the Attributes Inspector.
If you are creating a separate .xib file for your UITableViewCell you need to call this method on your UITableView in code somewhere:
registerNib:forCellReuseIdentifier:
If you are doing everything in code and just using a UITableViewCell subclass that knows how to layout itself then you need to call this method on your UITableView:
registerClass:forCellReuseIdentifier:
Here is a link to the reference docs

iPhone - Static UITableView with >1 sections using Interface Builder

I added a new TableView in my application. I changed the cell-type to static and dragged some labels into the cells. Now i want to access the cells programmatically. For example: Cell 4 in Section 3 should open safari with google.com.
I created a new UITableViewController-class. Then i changed the number of sections to 3, and added a switch/case statement to the the numberofcellsinsection method.
If i run the app and open up the table view, the app crashes. Can someone help me, with setting up the TableView ?
Thanks!
EDIT
Here is the 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'
*** First throw call stack:
I found a solution which is working.
i edited the cellForRowAtIndexPath method like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
return cell;
}
Now i can access my static cells with the if statements for example:
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 2){
if (indexPath.row == 1){
NSLog(#"Tap");
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"http://www.google.com"]];
}
}
}

Xcode unable to dequeue a cell with identifier

my work is about `UITableView. Each time I run my project, this error appears :
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell1 - must register a nib or a class for the identifier or connect a prototype cell in a storyboard
I checked a hundred times my cell identifier in my storyboard and in my code are the same.
Code (defaut code from UITableViewController) :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell1";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
return cell;
}
Picture of Table View Cell properties :
I created and implemented a subclass of UITableViewCell for my cell.
Any idea why this is not working ?
Any way (line of code) to know what is the identifier of a cell ?
Thanks
Edit : Screenshot of my interface builder.
Edit 2 : Text of customCell.h
#import <UIKit/UIKit.h>
#interface customCell : UITableViewCell
#end
New error appears when I run the project :
[<choixActiviteViewController 0x7591ac0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Cell1.
choixActiviteViewController is a subclass of UITableViewController and is the custom class of Choix Activite View Controller.
Instead of:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
Try:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if this does not work then, also add:
if (cell == nil) {
cell = [[customCell alloc] init];
}
Ok, your problem is that you're using Static cells, instead of Prototype cells. Just change your UITableView Content type.
Ok, my project finally works. Some errors appeared about things I've deleted and I can't find anymore.
I've just deleted every TableViewCell I had to create a new unique UITableViewCell with the following properties :
class : customCell
Style : Basic (but it works also with Custom)
Identifier : Cell1
Thanks for your help ssantos, Abdullah Shafique and bilobatum.
If your table cell is a subclass of UITableViewCell, then you're not using the "Basic" style of cell. Change the style setting in the attributes inspector to Custom.
Also, make sure the Class in the table cell's Identity inspector is set to your custom table cell subclass.
I suppose you'r using static cells. If you'r doing that consciously - just delete thous methods from your .m file:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
}
try to use customCell class instead UITableViewCell class.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell1";
customCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
return cell;
}
If you are intentionally using Static UITableViewCells, then you don't have to implement the normal UITableView population methods (numberOfSectionsInTableView:, tableView:numberOfRowsInSection:, tableView:cellForRowAtIndexPath:).
The UITableView will automatically populate from the cells defined in your storyboard. You do end up using the tableView:cellForRowAtIndexPath: in order to format the data in the cells. You use [super tableView:cellForRowAtIndexPath:] to get the tableViewCell and then ReuseIdentifier, tags, or indexPath to match the cell to the data that goes with it.
The reason for this issue is very clear from the exception:
One Solution to this problem is
register a class for the identifier
In Swift this can be done as follows
tableView.registerClass(UITableViewCell.classForKeyedArchiver(), forCellReuseIdentifier: "your_reuse_identifier")
In my case the Storyboard where I had defined the missing UITableViewCell was localised.
Comment out all of the code in application:didFinishLaunchingWithOptions(AppDelegate) but remain return YES, and try it again.
I was facing this issue when presenting the UITableViewController having a custom cell from another viewcontroller. As a workaround I instantiated it from the storyboard and that solved the issue.
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "YourTableViewController")
self.present(controller, animated: true, completion: nil)

Custom UITableViewCells Alloc Problrm

So I have custom UITableViewCells (made with storyboard), and when I do not literally alloc, init the cells, the app crashes. However, since they are custom cells, I don't know how to alloc/init them.
This code crashes:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TableViewCells *cell = (TableViewCells *)[tableView dequeueReusableCellWithIdentifier:#"TableViewCellsID"];
return cell;
}
with this printed to the console:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
I understand this means its crashing because there is no cell allocated yet, however when I try to allocate it, I have to specify a cell style.
So, when I build the cell as follows, it doesn't crash:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TableViewCells *cell = (TableViewCells *)[tableView dequeueReusableCellWithIdentifier:#"TableViewCellsID"];
if (cell == nil)
cell = [[TableViewCells alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"TableViewCellsID"];
return cell;
}
The problem is the code that works (the second set), requires me to set a UITableViewStyle. And as far as I know, there is no UITableViewStyleCustom.
Any helps would be appreciated.
It crashes in first case because there is no cell to reuse, and you are calling dequeueReusableCellWithIdentifier.
EDIT -
For custom cell initialisation you can check following threads -
How to make custom TableViewCell with initWithStyle after 3.0
initWithFrame vs initWithStyle

Resources