unrecognized selector sent to instance on ios table view cell click - ios

I'm a very beginner to iOs. I'm going to view a list in table view controller. My application is a story board application. I did the following code to go to the next view.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
LawyerViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:#"LawyerViewController"];
dvc.lawyer = #"Thisara";//[self.myObject objectAtIndex:indexPath.row];
[self.navigationController pushViewController:dvc animated:YES];
}
in my LawyerViewController header file I defined the following property.
#property (nonatomic, strong) NSString *lawyer;
When I'm clicking on the cell, I've got following error.
2014-07-26 23:56:14.420 lawyerapp[3626:60b] -[UIViewController setLawyer:]: unrecognized selector sent to instance 0x8cdd1f0
2014-07-26 23:56:14.424 lawyerapp[3626:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController setLawyer:]:
unrecognized selector sent to instance 0x8cdd1f0'
How do I fix this.
Thanks in Advance!

You have not defined the class in storyBoard.
Go to your viewController in StoryBoard ->
than identity Inspector -> class -> Put the class LawyerViewController.
Clean,build and run

Related

Overriding didSelectRowAtIndexPath on a framework-provided view controller?

So I'm using the CoreAudioKit's CABTMIDICentralViewController to present a list of MIDI Bluetooth devices for the user to select. However, I want to be able to tell which device the user selected when they're done, but it doesn't seem Apple has added any way to do that.
So I'm trying to hack it by detecting when the user selects a row in the table:
DPBleMidiDeviceManager.h:
#import <CoreAudioKit/CoreAudioKit.h>
#interface DPBleMidiDeviceManager : CABTMIDICentralViewController
#end
DPBleMidiDeviceManager.m:
#import "DPBleMidiDeviceManager.h"
#implementation DPBleMidiDeviceManager
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"midi device selected %#", indexPath);
//either of these next lines crash, it makes no difference:
//[[tableView delegate] tableView:tableView didDeselectRowAtIndexPath:indexPath];
[super tableView:tableView didDeselectRowAtIndexPath:indexPath];
}
#end
The problem is, it's crashing on the last line saying there's no selector. Which is weird, because if I remove the super call, it doesn't crash, but it also doesn't correctly connect to the BLE device, like it would if I was not overriding that delegate call.
Is this just something Apple does so you can't access their tables? Why would they build a UI view like this and let you call it, but not give you any information about what the result was? Am I missing some standard way to do this?
EDIT: here's the details of the crash with the super call:
2015-10-29 15:14:37.039 [626:338267] midi device selected <NSIndexPath: 0x1473ae20> {length = 2, path = 0 - 3}
2015-10-29 15:14:37.039 [626:338267] -[DPBleMidiDeviceManager tableView:didDeselectRowAtIndexPath:]: unrecognized selector sent to instance 0x147f34e0
2015-10-29 15:14:37.040 [626:338267] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DPBleMidiDeviceManager tableView:didDeselectRowAtIndexPath:]: unrecognized selector sent to instance 0x147f34e0'
*** First throw call stack:
(0x2b3cdfef 0x3967dc8b 0x2b3d3409 0x2b3d11bf 0x2b300e78 0xaa165 0x2eb3956b 0x2ebe843b 0x2ea9da91 0x2ea1838f 0x2b393fed 0x2b3916ab 0x2b391ab3 0x2b2de201 0x2b2de013 0x32aab201 0x2ea82a59 0x88447 0x39c09aaf)
libc++abi.dylib: terminating with uncaught exception of type NSException
That's not how you call super. It should be
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"midi device selected %#", indexPath);
[super tableView:tableView didDeselectRowAtIndexPath:indexPath];
}

Call method from another class in a UIButton

I have a custom UITableViewCell with a class linked to it called customCell.m. (I didn't use xib.) In the cell there is a button. Is there a way to create the buttons action on the mainVC.m file, as apposed to customCell.m?
Update
Here is the code I tried implementing. What I did is, I called a method from mainVC.m.
CustomCell.m
- (IBAction)myButton:(id)sender
{
CategorieViewController *mainVC = [[CategorieViewController alloc] init];
[mainVC myMethod];
}
MainVC.m
- (void)myMethod:(id)sender
{
UITableViewCell *clickedCell = (UITableViewCell *)[[[sender superview] superview] superview];
NSIndexPath *clickedButtonPath = [self.myTableView indexPathForCell:clickedCell];
NSLog(#"%#", clickedButtonPath);
}
CategorieViewController myMethod]: unrecognized selector sent to instance 0x7fd2dbd52a00
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CategorieViewController myMethod]: unrecognized selector sent to instance 0x7fd2dbd52a00'
You're calling myMethod, but the method is actually myMethod: and takes the sender as a parameter. Try changing:
[mainVC myMethod];
to:
[mainVC myMethod:sender];
Also, any sender you currently pass to myMethod: as a parameter, won't belong to mainVC's tableview yet because you're creating a brand new CategorieViewController instance to perform the method call and its table has never been loaded.
Assuming MainVC is the visible view controller, you can change:
CategorieViewController *mainVC = [[CategorieViewController alloc] init];
to:
UINavigationController *nav = (UINavigationController*)self.window.rootViewController;
CategorieViewController *mainVC = (CategorieViewController*)nav.visibleViewController;
to get the current the current MainVC instance with the loaded tableview.

Add row to UITableViewController from child

I have UIViewController that performs a login check with the code below, and a UITableViewController as its parent controller. I'm trying to add another row to the UITableViewController after switching back to it, however I'm getting the following error:
[UINavigationController insertNewObject:]: unrecognized selector sent to instance 0x14de164d0
2014-03-08 17:00:27.379 MyApp[2562:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController insertNewObject:]: unrecognized selector sent to instance 0x14de164d0'
-
if(loginSuccess)
{
[self.navigationController popViewControllerAnimated:YES];
[self.navigationController performSelector:#selector(insertNewObject:) withObject:#"Another Row"];
}
The method definition of insertNewObject is:
- (void)insertNewObject:(NSString *)name
{
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
[_objects insertObject:name atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
Can someone help me with what I'm doing wrong?
You're calling insertNewObject on a UINavigationController not your UITableViewController.
Try creating a property on your UIViewController that points to the original TableViewController and calling it through the property. Or calling it when the TableViewController reappears.

Adding a Navigation to a View Controller with a TableView

I'm trying to add (or have) a navigation bar (or items) on the top of a View controller and and a tableview right below the navigation bar. The problem I'm having is when I set the tableview's datasource to View Controller, my app will crash (setting the tableview's delegate to View controller doesn't). For now, the code for the tableview are in the default ViewController.m. Do I have the tableview's code in the right place or did I connect something improperly?
Here's the error that it gives me:
2013-10-10 15:14:48.442 SomeApp[15058:a0b] -[UIViewController >tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x8d42450
2013-10-10 15:14:48.450 SomeApp[15058:a0b] *** Terminating app due to uncaught exception >'NSInvalidArgumentException', reason: '-[UIViewController >tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x8d42450'
Make sure your view controller adheres to the proper protocols:
CustomViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
And add the necessary methods from these protocols to your implementation. These are the documentation links for your ease:
UITableViewDelegate Protocol Reference
UITableViewDataSource Protocol Reference
You are missing some methods that are required for your tableview to work,
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
More information on UITableViewDataSource Protocol Reference

Controller has no segue with identifier

I connected my UITableViewController to a NavigationController with ctrl, defined the segue as "modal" and defined the segue identifier "DetailEvent".
In the class of my UITableViewController I added this code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"Row Selected = %i",indexPath.row);
[self performSegueWithIdentifier:#"DetailEvent" sender:self.view];
}
Error:
Row Selected = 1
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<AvailableEventsController: 0xa335500>) has no segue with identifier 'DetailEvent''
*** First throw call stack:
(0x175b012 0x1580e7e 0x5aa492 0xa6b53fa 0x103a0 0x5778d5 0x577b3d 0xf7ee83 0x171a376 0x1719e06 0x1701a82 0x1700f44 0x1700e1b 0x23ee7e3 0x23ee668 0x4c865c 0xbf7d 0x2755)
libc++abi.dylib: terminate called throwing an exception
What am I doing wrong here?
I was working on a different UIViewController in the StoryBoard.

Resources