NSTableView may not respond to "_LocationOfColumn" - cocoa

Trying to squash this warning / bug in my code not sure how to approach this error. Everything in the code works so I am unclear as to why its throwing this error.
"Warning: NSTableView may not respond to "_LocationOfColumn
- (void) _locationOfColumn: (int) aColumn
{
SampleListArrayController *arrayController;
arrayController = (SampleListArrayController *) SampleListController;
if(( [ arrayController libraryIsSelected ] ) && ( aColumn == 4 ))
{
return;
}
[ super _locationOfColumn: aColumn ]; <-- Error on this line.
}
Any help or direction is appreciated.

Well as i mentioned in my comments your method does not respond to the tableview. So i would recommend that in spite of using your custom method for detrmining location of column use below NSTableView delegate method which will Sent to the delegate to allow or prohibit the specified column to be dragged to a new location.:-
-(BOOL)tableView:(NSTableView *)tableView
shouldReorderColumn:(NSInteger)columnIndex toColumn:(NSInteger)newColumnIndex

Related

Edit the tableview rows for deleting multiple rows in Tableview in iOS giving error

I follow the link
select multiple rows from uitableview and delete
I write the code in the delete method as
(void)deleterows:(id)sender {
NSArray *array=[selectedRows allObjects];
NSLog(#"indexes are::%#",array);
[self.tableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationTop];
}
but it is giving error as Terminating app due to uncaught exception NSInvalidArgumentException
reason: -[__NSCFNumber row]: unrecognized selector sent to instance 0x9161b50
Please tell me where did I made mistake.
Since you are targeting >= iOS5 you could simply use:
self.tableView.allowsMultipleSelection = YES;
and then
(void)deleterows:(id)sender {
NSArray *array= [self.tableView indexPathsForSelectedRows];
NSLog(#"indexes are::%#",array);
[self.tableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationTop];
}
without using the selectedRows array at all.
If you want multiple selection only in edit mode, you should set
self.tableView.allowsMultipleSelection = YES;
Have a look at allowsMultipleSelectionDuringEditing in the Documentation.
selectedRows is an array of NSNumbers. deleteRowsAtIndexPaths:withRowAnimation: expects an array of NSIndexPath objects. The answer you linked clearly states that you should create such array:
in your deleteRows method, iterate through the selectedRows set, building up an array of indexPaths, delete these rows from your data
model, then call (with your preferred animation type):
[self.myTableView deleteRowsAtIndexPaths:arrayOfIndexPathsToDelete
withRowAnimation:UITableViewRowAnimationTop];

How to specify a group when displaying an ABPeoplePickerNavigationController? [duplicate]

How do you specify a group when initially displaying an ABPeoplePickerNavigationController (so it doesn't automatically display "All Contacts")?
Yeah, I do. I had to make it work.
Set your class as the delegate of the people picker (pp.delegate = self;)
Then implement:
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if([navigationController.viewControllers count] > 1) {
navigationController.delegate = nil;
[navigationController popViewControllerAnimated:NO];
}
}
It seems to work best with animation off, but still works with it on but sort of goofy. Only tested on simulator.
D

View Based Table Cells on OS X not showing data properly

So I admit to being a total noob to cocoa, so I offer a noob question. I'm probably just missing the dumb obvious somewhere but i just cant seem to get my table to populate data.
I'm following the table view playground example but everytime i try to mimic the Basic TableView Window the first row becomes the height of the number of rows i added (at least thats what it looks like. Here is my code:
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
{
NSString *identifier = [tableColumn identifier];
if ([identifier isEqualToString:#"filename"]) {
// We pass us as the owner so we can setup target/actions into this main controller object
NSTableCellView *cellView = [fileBrowserTable makeViewWithIdentifier:identifier owner:self];
// Then setup properties on the cellView based on the column
cellView.textField.stringValue = [fileList filenameAtIndex:row];
cellView.imageView.objectValue = [[NSWorkspace sharedWorkspace] iconForFile:[fileList fullPathAtIndex:row]];
return cellView;
}
else if ([identifier isEqualToString:#"path"]) {
NSTextField *textField = [fileBrowserTable makeViewWithIdentifier:identifier owner:self];
textField.objectValue = [fileList pathAtIndex:row];
return textField;
}
else if ([identifier isEqualToString:#"preview"]) {
NSTextField *textField = [fileBrowserTable makeViewWithIdentifier:identifier owner:self];
textField.objectValue = [fileList previewAtIndex:row];
return textField;
}
return nil;
}
I think its worth mentioning that when using a the old school text field cell, I have no problems displaying data (of course the above code is different in that case) so im positive sure its not a problem with my data structure that holds the values. I have also set the correct delegate and data source
The cell using the 'filename' identifier uses the 'image and text table view cell' while the others use just a 'text table cell view'. Neither of them work so i'm guessing something is wrong with how I set my table up. But when comparing my table with that of the example, it's just a spitting reflection (minus identifiers file names).
One thing that I notice that I can't quite figure out is that the example says:
The NSTableView has two reuse identifier assocations: "MainCell" and "SizeCell" are both associated with the nib ATBasicTableViewCells.xib
I don't really understand this statement. However that being said, the example doesn't contain any ATBasicTableViewCells.xib nor does it have any associations with it (code or ib) that I can find.
Have you tried to set the rowSizeStyle of the NSTableView to NSTableViewRowSizeStyleCustom?
[UPDATE] Re-reading your question, it's not clear for me what your problem is. The solution I have given is related to problems with the size of each cell which is not taken into account unless the rowSizeStyle is set to custom.

Show NSSegmentedControl menu when segment clicked, despite having set action

I have an NSSegmentedControl on my UI with 4 buttons. The control is connected to a method that will call different methods depending on which segment is clicked:
- (IBAction)performActionFromClick:(id)sender {
NSInteger selectedSegment = [sender selectedSegment];
NSInteger clickedSegmentTag = [[sender cell] tagForSegment:selectedSegment];
switch (clickedSegmentTag) {
case 0: [self showNewEventWindow:nil]; break;
case 1: [self showNewTaskWindow:nil]; break;
case 2: [self toggleTaskSplitView:nil]; break;
case 3: [self showGearMenu]; break;
}
}
Segment 4 has has a menu attached to it in the awakeFromNib method. I'd like this menu to drop down when the user clicks the segment. At this point, it only will drop if the user clicks & holds down on the menu. From my research online this is because of the connected action.
I'm presently working around it by using some code to get the origin point of the segment control and popping up the context menu using NSMenu's popUpContextMenu:withEvent:forView but this is pretty hacktastic and looks bad compared to the standard behavior of having the menu drop down below the segmented control cell.
Is there a way I can have the menu drop down as it should after a single click rather than doing the hacky context menu thing?
Subclass NSSegmentedCell, override method below, and replace the cell class in IB. (Requires no private APIs).
- (SEL)action
{
//this allows connected menu to popup instantly (because no action is returned for menu button)
if ([self tagForSegment:[self selectedSegment]]==0) {
return nil;
} else {
return [super action];
}
}
I'm not sure of any built-in way to do this (though it really is a glaring hole in the NSSegmentedControl API).
My recommendation is to continue doing what you're doing popping up the context menu. However, instead of just using the segmented control's origin, you could position it directly under the segment (like you want) by doing the following:
NSPoint menuOrigin = [segmentedControl frame].origin;
menuOrigin.x = NSMaxX([segmentedControl frame]) - [segmentedControl widthForSegment:4];
// Use menuOrigin where you _were_ just using [segmentedControl frame].origin
It's not perfect or ideal, but it should get the job done and give the appearance/behavior your users expect.
(as an aside, NSSegmentedControl really needs a -rectForSegment: method)
This is the Swift version of the answer by J Hoover and the mod by Adam Treble. The override was not as intuitive as I thought it would be, so this will hopefully help someone else.
override var action : Selector {
get {
if self.menuForSegment(self.selectedSegment) != nil {
return nil
}
return super.action
}
set {
super.action = newValue
}
}
widthForSegment: returns zero if the segment auto-sizes. If you're not concerned about undocumented APIs, there is a rectForSegment:
(NSRect)rectForSegment:(NSInteger)segment
inFrame:(NSRect)frame;
But to answer the original question, an easier way to get the menu to pop up immediately is to subclass NSSegmentedCell and return 0 for (again, undocumented)
(double)_menuDelayTimeForSegment:(NSInteger)segment;

cocoa - comparing dates, warning passing argument one of 'compare:' from distinctive objective-c type

I've had a look through similar queries on here and elsewhere but i still can't seem to resolve my problem.
I am trying to see whether a date stored in a mutable dictionary in an array is between two other dates. The piece of code generating the warning is:
if ( [[[records objectAtIndex:( i )] objectForKey:#"Date"] compare:userStartDate] == NSOrderedDescending && [[[records objectAtIndex:( i )] objectForKey:#"Date"] compare:userEndDate] == NSOrderedAscending ) {
As it may be relevant, userStartDate is created as follows:
- (id)initWithArray:(NSMutableArray *)newRecords andWithUserStartDate:(NSDate *)newUserStartDate andWithUserEndDate:(NSDate *)newUserEndDate {
if (self = [super init]) {
[self setRecords:newRecords];
[self setUserStartDate:newUserStartDate];
[self setUserEndDate:newUserEndDate];
}
return self;
}
Called from another part of code by:
summariser = [[Summariser alloc]initWithArray:records andWithUserStartDate:[userTimesStartDatePicker dateValue] andWithUserEndDate:[userTimesEndDatePicker dateValue]];
And the record itself as:
[record setObject:[datePicker dateValue] forKey:#"Date"];
I hope this is clear and that someone can help.
Thanks
I think the problem here is that objectForKey: returns id, so the compiler can't be sure it's an instance of NSDate and triggers the warning.

Resources