cocoa

ObjC/Cocoa class for converting size to human-readable string?

Is there a simple way to do something like.. [NSMagicDataConverter humanStringWithBytes:20000000] ..which would return "19.1MB"? ...

Convert characters to HTML Entities in Cocoa

I am currently trying to put together an URL where I specify some GET parameters. But I want to use japanese or other characters too in this URL. Is there a way to convert a NSString to a string containing the HTML entities for the 'special' characters in my NSString? I am currently using the following code, which seems to work, except...

Observing Properties with Custom Accessors

Let's say I want to observe the hidden property on UIView: @property(nonatomic, getter=isHidden) BOOL hidden Do I add an observer for the keypath hidden or isHidden? ...

Displaying UITableViewCell's side by side, on the same row (As in Contacts -> Info)

If one navigates to the iPhone's Phone app, then goes to Contacts -> Info (on any contact).. you will see at the bottom of the contact there are two adjacent UITableViewCells, on the same row. In this particular case, they are "Text Message" and "Add to Favorites" How is this layout achieved? If there's any examples out there, that woul...

Cocoa strategy for pointer/memory management

I see a lot of code, particularly in Apple example code, that resembles the following: EditingViewController *controller = [[EditingViewController alloc] initWithNibName:@"EditingView" bundle:nil]; self.editingViewController = controller; [controller release]; Is there any reason in particular that the approach above proves...

NSMutable NSArray Array - How can I avoid all these lines and use a dimensional or 3D array?

enter code here- (void)viewDidLoad { NSMutableArray *imageViewArray= [[NSMutableArray alloc] init]; for ( int i = 1; i < 10 ; i++ ) { NSString *imgName = [NSString stringWithFormat:@"pic%i.jpg", i]; UIImage *img = [UIImage imageNamed:imgName]; [imageViewArray addObject:img]; } self.gallery = imageViewArray; [imageViewArray release]...

Core Animation - Sheet-like Window Sliding

How difficult would it be to use core animation to make an NSView slide in an out of view like a sheet? Generally speaking, what would be involved in accomplishing this? I've been reading through the CA documentation, but it's been hard for me to pinpoint which parts are relevant to what I want to do since I have no experience with the f...

Objective-C use of #import and inheritance

I have a hypothetical UIViewController class named "foo". foo inherits from class bar and class bar #import's "Class A", a class which foo uses extensively. The problem is, when I'm using an instance of class A in foo, I don't get any compiler errors, but I do get a warning for instance, that an instance of Class A does not respond to a ...

Use of @synthesize/@property in Objective-C inheritance

If you have Class A with an instance var "foo" which has a @property/@synthesize directive, and Class B inherits from Class A, does it also need to @property/@synthesize "foo"? The reason I ask is because when I try to use Class B's "foo", the calling class says that "foo" is not something of a structured union or a member, which makes m...

Set default values for a global variable in a custom class?

I have a custom class that has quite a few accessor methods for customizing it. My question is, if a programmer uses this class and doesn't bother to assign values for ALL of these methods because he doesn't know about them or doesn't want to bother, how can I make the class assume a default view? I can't use awakeFromNib, because that w...

Binding two different model-key-paths to the same NSArrayController selection

Say I have the following array of dictionaries: { { isoName => en, fullName => English, localName => English }, { isoName => de, fullName => German, localName => Deutsch }, { isoName => fr, fullName => French, localName => français } } How ...

NSTimeInterval to readable NSNumber

NSTimeInterval == double; (e.g. 169.12345666663) How can I round up this double so that there are only 2 digits left after the "dot"? It would be very good if the result is a NSNumber. ...

What's the best layout for a scrollable iPhone "detail view" with variable content?

I'm building a navigation controller based iPhone application and am curious how to go about building the detail view for my application. The part that's complicating my endeavor is: What UI elements/hierarchy should I employ to create a variable-height yet scrollable detail view? A great example of my goal is an arrangement like the m...

Given an IBOutlet to an NSTextField that is bound to some NSDate, how can I programatically set a new date?

I have a nice chunk of reuable code I'm trying to edit and keep clean of the details. I'd like to be able to edit the NSDate some NSTextField is bound to. The only thing I have is the IBOutlet to the text field. Is this possible? ...

Disable Option-Enter line breaks in NSTextField?

I want to disallow entering a new-line character in my NSTextField, which by default is possible by typing Option-Enter (or Option-Return). While I found some pages explaining how to allow line breaks without having to use the Option modifier, I couldn't find anything for disabling line breaks altogether. How can this be done? ...

Need a background process. Thread?

Hello, I need a background process to run every minute or so. I do not want this process to interfere with the responsiveness of the rest of the app. Would this be a good candidate for a thread? If so, how would you suggest I set up the thread - in particular, what classes/methods would be good to look into? ...

iPhone: replacing a cell's view with UITextField

I'm basically trying to add a UITextField to a UITableViewCell upon tableView:commitEditingStyle:forRowAtIndexPath:. On insert, I want to add a UITextField over the existing cell. I setup the textField with something like this: -(void) setUpIndexField { inputField = [[UITextField alloc] init]; inputField.textAlignment = UITextA...

Best way to escape characters like newline and double-quote in NSString

Say I have an NSString (or NSMutableString) containing: I said "Hello, world!". He said "My name's not World." What's the best way to turn that into: I said \"Hello, world!\".\nHe said \"My name\'s not World.\" Do I have to manually use -replaceOccurrencesOfString:withString: over and over to escape characters, or is there an easie...

Copy/Paste Not Working in Modal Window

In my cocoa app I am displaying a NSPanel as a modal 'window' of another NSPanel using: [modalPanel setWorksWhenModal:YES]; [[NSApplication sharedApplication] beginSheet:modalPanel modalForWindow:mainPanel modalDelegate:nil didEndSelector:nil contextInfo:nil]; This works, however the NSTextField's that show up in that modal 'window' a...

How can I get the icon for a storage device in Mac OS X?

I've found my devices using IOServiceGetMatchingServices and got the property dictionary like this: kernResult = IORegistryEntryCreateCFProperties(nextMedia, (CFMutableDictionaryRef *)&props, kCFAllocatorDefault, 0); From that dictionary I can extract the informations f...