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];
}
Related
The following problem occurs in my project, when i pressed and hold a backbutton (uibarbuttonitem) and a tableview row. And letting go the tableview row and followed by letting go the backbutton the following error occurs:
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'.
I have figured out the problem here is that the tableview didselectrowatindexpath has wrong indexpath.
Case: A uibarbuttonitem and a tableview row is pressed and hold simultaneously.
In situation 1: The uibarbuttonitem is letting go and followed by letting go the tableview row.
Result: Selector for uibarbuttonitem is called. (In my case no error.)
In situation 2: The tableview row is letting go and followed by letting go the uibarbuttonitem.
Result: Selector for uibarbuttonitem is called and followed by the delegate methods of tableview. (In my case the error above occurs.)
- (void)backbutton {
self.itemList = [self getOldItem];
[self.tableView reloadData];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// It crash on this line.
Model *model = [[self.itemList objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
[model show];
}
Does anyone know if this is a normal behavior for which order the selector methods of those button are called? And how i should handle this?
As a follow up to this question: Skip/ignore method in iOS, I'm trying to implement separate delegates for my UITableView in iOS7 and iOS8.
So, as a first step, in viewDidLoad of my MyTableViewController, I added the following code:
if ([[[UIDevice currentDevice] systemVersion] compare: #"8.0" options: NSNumericSearch] != NSOrderedAscending)
{
[self.tableView setDelegate: [[MyTVDelegate alloc] initWithIdentifier: myTVCellIdentifier]];
}
else
{
[self.tableView setDelegate: [[MyTVDelegate7 alloc] initWithIdentifier: myTVCellIdentifier]];
}
I'm adding an identifier, since I will have to apply this to multiple view controllers (or I may have just create a delegate class for each TV, I haven't figured that out yet).
I'm using CoreData, so my dataSource is an NSFetchedResultsController.
Then, I have the following for MyTVDelegate/myTVDelegate7:
#import "MyTVDelegate.h"
#implementation MyTVDelegate
- (instancetype)initWithIdentifier: (NSString *) identifier
{
if ([super init])
{
self.identifier = identifier;
}
return self;
}
#end
#implementation MyTVDelegate7
- (CGFloat)tableView: (UITableView *)tableView heightForRowAtIndexPath: (NSIndexPath *)indexPath
{
return 44;
}
- (CGFloat)tableView: (UITableView *)tableView estimatedHeightForRowAtIndexPath: (NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}
#end
If I run this, I'm getting the following runtime error in iOS7:
2015-01-18 10:42:51.894 -[__NSArrayI tableView:estimatedHeightForRowAtIndexPath:]: unrecognized selector sent to instance 0x7b9dd220
2015-01-18 10:42:57.731 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI tableView:estimatedHeightForRowAtIndexPath:]: unrecognized selector sent to instance 0x7b9dd220'
on iOS8, there is no crash.
The instance 0x7b9dd220 is an NSArray. My hunch is that it crashes, because the indexPath is invalid because the delegate and 'dataSource' are now separate?
I've tried moving the call to performFetch to either before or after setting the delegate, but I get the same error.
How do I fix this, should I for instance move all the NSFetchedResultsController code to the new delegate class as well?
self.tableView setDelegate: assigns a weak reference; if you don't hold your own reference to this object, it will get collected. This is why you're seeing the crash. The system has collected the memory that was assigned to your delegate, then reassigned the memory to an NSArray. Your table tries to call methods on the delegate and can't because NSArray does not respond to them.
Alongside the self.tableView property definition, define another property:
#property (strong) id<UITableViewDelegate> myTableViewDelegate;
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
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.
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.