i have looked through basically every single stack overflow question on this, but i cant find an answer. None of the answers seem to work.
I am writing an application that has a tableview in it, with a uitableview as a subview.
The uitableview is datasource and delegate connected to a class called xvalues, which is a subclass of uitableviewcontroller. i also have a class, where i load a custom uitableviewcell. This all doesn't cause any errors.
Here is my code for the uitableview, in xvalues:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
tableviewcell *cell = [[tableviewcell alloc]initWithFrame:CGRectZero];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:#"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
*/
}
I removed some commented out methods such as can edit row at index path and commit editing style.
In cellforrowatindexpath, tableviewcell is my custom cell class.
From this, when i run my code, it loads up my uitableview, with 1 cell, with my custom cell.
However, now, if i click and drag, it works for dragging about an inch, and then suddenly crashes with the error:
2012-07-16 12:14:16.957 spreadsheet[68717:f803] -[__NSCFString tableView:cellForRowAtIndexPath:]: unrecognized selector sent to instance 0x6894400
2012-07-16 12:14:16.960 spreadsheet[68717:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString tableView:cellForRowAtIndexPath:]: unrecognized selector sent to instance 0x6894400'
*** First throw call stack: blah blah blah
It also happens when i click on the row, but i think that is because of my did select row at index path method.
If anyone could help me it would be amazingly helpful.
Your table view controller is getting deallocated. Make sure you’re retaining your xvalues instance (or assigning it to a strong property on something, like your app delegate) wherever you’re creating it.
Related
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section
{
return [recieps count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"RecipeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [recieps objectAtIndex:indexPath.row];
return cell;
}
I want to display recipes list in Navigation table view but I am getting errors like unrecognized selector sent to instance 0x7f8c61709f80
"Unrecognized Selector" in iOS means you're attempting to call a method that the object you're asking doesn't understand.
You're saying [someObject doThisMethod], but someObject doesn't know what you're talking about.
Either the method doesn't exist for that object & needs to be added, or there's an issue with your storyboard connections or classes.
The error tells you what the problem is & where:
-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7fec31c38af0
This tells you that a tableView instance (at memory address 0x7fec31c38af0) received the message numberOfRowsInSection:, but it doesn't know what to do.
If you're using a custom class for your UITableView, make sure you've set it properly in your storyboard. Also make sure you've properly hooked up both UITableViewDelegate and UITableViewDataSource.
Since it doesn't recognize this required UITableViewDataSource protocol method, it's likely you forgot to add that or hook it up. Double-check your storyboard connections and that your UITableView class actually conforms to the UITableViewDataSource protocol.
Also, it's "recipe" ... you have misspelled it "recieps" in several places...
In your above code number of section method not called. Please add the below line of code
(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
Note:
Then you are calling some method that is not exist in your controller.That's why you got the 'unrecognized selector' error message on console. Try to figure out the method and check again.
I create a UITableView when a user presses a button, set it's delegate and data source to the current controller (which implements both UITableViewDelegate and UITableViewDataSource protocols), add it as a subview to the controller's view and implement the data source methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
Whenever I scroll the table view, the application crashes with
[UITableView currentPage]: unrecognized selector sent to instance 0x11365c00
where 0x11365c00 is the tableView. If I don't set the tableView's delegate and only set the data source, it doesn't crash. This behavior is the same if I return 0 in numberOfRowsInSection, so that nothing is added to the tableView and there is no crash related to my data. Any help would be great!
The crash occurs because you are sending a message -currentPage to an object that can't handle it.
And actually tableviews doesn't have this method in their interfaces, unless you are using a category. So the question is which object n your implementation file should handle this message?
Reason:
[someObjectHere currentPage]; // Here someObjectHere is really a table view(UITableView type)
If you have table view class and forgot to define the currentPage method, then define it there. That's y it crashed the app.
If you have currentPage method in your view controller then you have to make sure that someObjectHere is a your View controller.
[self currentPage];
I am trying to load a UITableViewController however i keep getting this error and my app crashes.
* Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2935.137/UITableView.m:5439
2014-04-15 00:40:55.244 TradingGame[966:60b]* 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'
Heres my code
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath:indexPath];
if (cell) {
// will eventually put labels etc here.
}
return cell;
}
Here is where i call my UITableViewController to push to the screen:
if (indexPath.row == 1) {
Foo *foo = [[Foo alloc] init];
[self.navigationController pushViewController:foo animated:YES];
}
Problem solved. Thanks to #Paulw11 for pointing out about instantiating the table view.
Those who have a similar issue to me make the following changes to your instantiation of tableview:
Try this first:
Foo *foo = [[Foo alloc] init];
[self.navigationController pushViewController:foo animated:YES];
If that does not work you may have a similar problem to me therefore use this code:
Foo *foo = [self.storyboard instantiateViewControllerWithIdentifier:#"Foo"];
[self.navigationController pushViewController:foo animated:YES];
Replace classes where applicable and "Foo" should be equal to the Storyboard ID of the view controller you are trying to instantiate.
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"]];
}
}
}
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