NSTableCell setDataCell disables editing - nstableview

I have a NSTableView which I dynamically add columns. I've just added a call to setDataCell to customize my cell. The code looks like:
for(NSUInteger columnIndex = 0; columnIndex < resultSet.columNames.count; ++columnIndex)
{
NSTableColumn * newColumn = [[NSTableColumn alloc] initWithIdentifier: [NSString stringWithFormat: #"%ld", columnIndex]];
[newColumn.headerCell setAlignment: NSCenterTextAlignment];
[newColumn.headerCell setStringValue: resultSet.columNames[columnIndex]];
[newColumn setDataCell: [[HSDisclosureTextFieldCell alloc] init]];
[newColumn setEditable: YES];
[resultsTableView addTableColumn: newColumn];
if(newColumn.width < 60) [newColumn sizeToFit];
} // End of column loop
If I remove the call to setDataCell then I can still double click my entry and edit it.
I have minimized the HSDisclosureTextFieldCell contains the following (no overrides):
#interface HSDisclosureTextFieldCell : NSTextFieldCell
{
}
But I still cannot double click to edit the field anymore.
Any ideas where I'm going wrong?

Turns out even though I am doing:
[newColumn setEditable: YES];
and have:
- (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
implemented, I needed to switch my setDataCell to be:
HSDisclosureTextFieldCell * cell = [[HSDisclosureTextFieldCell alloc] init];
[cell setEditable: YES];
[newColumn setDataCell: cell];
Now that I have done that, everything seems to be working properly.

Related

watchkit WKAlertAction openSystemURL

I am trying to show the User different Phone Numbers on Apple Watch and he clicks on one than phone call alert should appear. I'll do it like this but the Alert is just dismissed without call action:
NSMutableArray *tempArray = [[NSMutableArray alloc] initWithCapacity:0];
WKExtension *myExt = [WKExtension sharedExtension];
for (NSString *phone in arr) {
NSString *tel = [NSString stringWithFormat:#"tel:%#",phone];
WKAlertAction *act = [WKAlertAction actionWithTitle:tel style:WKAlertActionStyleDefault handler:^(void){
[myExt openSystemURL:[NSURL URLWithString:phone1]];
}];
[tempArray addObject:act];
}
NSString *titleMessage = #"Call";
NSString *textMessage = #"Please select the number you want to call.";
NSString *cancel = #"Cancel";
WKAlertAction *act = [WKAlertAction actionWithTitle:cancel style:WKAlertActionStyleDestructive handler:^(void){
}];
[tempArray addObject:act];
[self presentAlertControllerWithTitle:titleMessage message:textMessage preferredStyle:WKAlertControllerStyleAlert actions:tempArray];
Buttons are shown as expected and the Handler is also called with the correct Phone Number. But it does not openSystemURL. Does somebody know why and how to fix? Thanks!
I think you forgot to add "tel" scheme ,Use below code :
[WKAlertAction actionWithTitle:#"tel" style:WKAlertActionStyleDefault handler:^(void){
[[WKExtension sharedExtension]openSystemURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel:%#",#"YOUR NUMBER"]]];
}];
About Apple URL Schemes

Apple - UISearchBar issue with UINavigationConroller

Using storyboard I have created one UINavigationController and two UITableViewContorllers:
(MasterViewContoller)
and
(Level2Contoller).
Both UITableViewControllers have UISearchBar at top. MasterViewContoller is set as root of UINavigationConroller.
Now the problem is that when I use below code to go to level2, I am not getting a seach bar on Level2Contoller.
level2Contoller *l2 = [[level2Contoller alloc]init];
[[self navigationController] pushViewController :l2 animated:YES];
Solution:
I used this:
level2Contoller * level2Contoller = [self.storyboard instantiateViewControllerWithIdentifier:#"id1"];
instead of:
level2Contoller *l2 = [[level2Contoller alloc]init];

How to navigate next tab while first tab view in process?

I have 4 tabs in UITabBarcontroller. My problem is i need to navigate to next tab by user click while first tab process in on going?? how to run the process on background??
Now second tab not working while the first tab view in process. I used PerformSelectorInBackground but it's not help me?? Can any one help me Please????
Am poor in english, can you understand my problem?
Yuva.M
Run your heavy process with NSThread.
Snippet from here:
- (IBAction) startThreadButtonPressed:(UIButton *)sender {
[NSThread detachNewThreadSelector:#selector(startTheBackgroundJob) toTarget:self withObject:nil];
}
- (void)startTheBackgroundJob {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// wait for 3 seconds before starting the thread, you don't have to do that. This is just an example how to stop the NSThread for some time
[NSThread sleepForTimeInterval:3];
[self performSelectorOnMainThread:#selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:NO];
[pool release];
}
- (void)makeMyProgressBarMoving {
float actual = [threadProgressView progress];
if (actual < 1) {
threadProgressView.progress = actual + 0.01;
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:#selector(makeMyProgressBarMoving) userInfo:nil repeats:NO];
}
}

Redraw NSTableView with new data from file when NSViewController re-loaded?

I have a Mac OS X Document based app that has multiple NSViewControllers that I switch between and each view displays data from plist files in NSTableViews based on the user selections in the previous NSViewController's NSTableView. The problem I have is that I can't figure out what function can be called, every time a NSViewController gets loaded, to read the correct data from a file to display in the NSTableView. For UIViewControllers I used the function family of viewDidLoad, viewWillAppear, but I haven't been able to find the corresponding functions for NSViewController.
Currently I am using awakeFromNib, which works fine, but only the first time the NSViewController gets loaded. I've tried loadView, but that collapses the NSView. I assume that I need to do more setup to use loadView.
I'm using the View Swapping code from Hillegass's book Cocoa Programming for MAC OS X which switches ViewControllers with the following code:
- (void)displayViewController:(ManagingViewController *)vc
curBox: (NSBox *)windowBox
{
// End editing
NSWindow *w = [windowBox window];
BOOL ended = [w makeFirstResponder:w];
if (!ended) {
NSBeep();
return;
}
NSView *v = [vc view];
NSSize currentSize = [[windowBox contentView] frame].size;
NSSize newSize = [v frame].size;
float deltaWidth = newSize.width - currentSize.width;
float deltaHeight = newSize.height - currentSize.height;
NSRect windowFrame = [w frame];
windowFrame.size.height += deltaHeight;
windowFrame.origin.y -= deltaHeight;
windowFrame.size.width += deltaWidth;
[windowBox setContentView:nil];
[w setFrame:windowFrame
display:YES
animate:YES];
[windowBox setContentView:v];
// Put the view controller in the responder chain
[v setNextResponder:vc];
[vc setNextResponder:windowBox];
}
and puts the NSView Controller in the responder chain.
Is there some function I can call to setup the view every time I swap NSViewControllers? Can I check that a NSViewController has become the firstResponder?
This post provided the answer.
I added the following code:
- (void)viewWillLoad {
}
- (void)viewDidLoad {
}
- (void)loadView {
[self viewWillLoad];
[super loadView];
[self viewDidLoad];
}
and at the beginning of displayViewController I added
[vc loadView]

NSAttributedString Strikethrough does not draw over entire length of text

I am inserting an NSAttributedString into an NSTableView, and depending on it's content I am adding attributes to its style dictionary.
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex {
NSAttributedString *theValue;
NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
[attributes setObject:[NSFont systemFontOfSize:11] forKey:NSFontAttributeName];
currentObject = [ticketsDataSource objectAtIndex:rowIndex];
if ([[currentObject valueForKey:aTableColumn.identifier] isKindOfClass:([NSString class])]) {
NSString *currentValue = [currentObject valueForKey:aTableColumn.identifier];
if ([currentValue isEqualToString:#"resolved"]) {
[attributes setObject:[NSColor colorWithCalibratedRed:0.344 green:0.619 blue:0.000 alpha:1.000] forKey:NSForegroundColorAttributeName];
}
if ([previousValue isEqualToString:#"resolved"]) {
[attributes setObject:[NSNumber numberWithInteger:NSUnderlinePatternSolid | NSUnderlineStyleSingle] forKey:NSStrikethroughStyleAttributeName];
}
theValue = [[NSAttributedString alloc] initWithString:currentValue attributes:attributes];
previousValue = currentValue;
}
As you can see, basically what happens is when it writes a string called "resolved" it knows that the very next column, which is the title column, gets a strikethrough. It works just fine, but for whatever reason, the strikethrough is not drawing over the entirety of the text!
Here is an image:
What is going on here?
Yet another weirdness with layer-backing. So I turned it off :(

Resources