Class method equivalent of -respondsToSelector:

Update after seeing your edit: A class object responds to respondsToSelector: just fine, as you’re probably aware. In a test application, I can do both of the following without any compiler warnings: NSLog(@”Responds to selector? %i”, [MyObject respondsToSelector:@selector(respondsToSelector:)]); NSLog(@”Responds to selector? %i”, [[MyObject class] respondsToSelector:@selector(respondsToSelector:)]); However, you’ve declared a protocol on your variable, so it … Read more

UISwitch in a UITableView cell

Setting it as the accessoryView is usually the way to go. You can set it up in tableView:cellForRowAtIndexPath: You may want to use target/action to do something when the switch is flipped. Like so: – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { switch( [indexPath row] ) { case MY_SWITCH_CELL: { UITableViewCell *aCell = [tableView dequeueReusableCellWithIdentifier:@”SwitchCell”]; if( … Read more

Add a running countup display timer to an iOS app, like the Clock stopwatch?

If you look in the iAd sample code from Apple in the basic banner project they have a simple timer: NSTimer *_timer; _timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timerTick:) userInfo:nil repeats:YES]; and the the method they have – (void)timerTick:(NSTimer *)timer { // Timers are not guaranteed to tick at the nominal rate specified, so this isn’t … Read more

Ignoring certificate errors with NSURLConnection

You could simply ignore the invalid certificate if you are not sending any sensitive information. This article describes how you could do that. Here is an example implementation by Alexandre Colucci for one of the methods described in that article. Essentially you want to define a dummy interface just above the @implementation: @interface NSURLRequest (DummyInterface) … Read more

Is it possible to NOT dismiss a UIAlertView

Yes. Subclass UIAlertView and then overload -dismissWithClickedButtonIndex:animated:, e.g. @implementation MyAlertView -(void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated { if (buttonIndex should not dismiss the alert) return; [super dismissWithClickedButtonIndex:buttonIndex animated:animated]; } @end Unofficially you can define a -(void)alertSheet:(UIAlertSheet*)sheet buttonClicked:(id)button; method to the delegate which will make it bypass -dismissWithClickedButtonIndex:animated:, but it’s undocumented, so I don’t know whether it’s suitable for you.

How to set kerning in iPhone UILabel

Old question, but you can do it now (easily). NSMutableAttributedString *attributedString; attributedString = [[NSMutableAttributedString alloc] initWithString:@”Please get wider”]; [attributedString addAttribute:NSKernAttributeName value:@5 range:NSMakeRange(10, 5)]; [self.label setAttributedText:attributedString]; For Nov 2013, Just to expand on this great answer, here’s some totally typical code. Usually you’d set the font as well. Note in the comments the old-fashioned way using … Read more

Non-retaining array for delegates

I found this bit of code awhile ago (can’t remember who to attribute it to). It’s quite ingenius, using a Category to allow the creation of a mutable array that does no retain/release by backing it with a CFArray with proper callbacks. @implementation NSMutableArray (WeakReferences) + (id)mutableArrayUsingWeakReferences { return [self mutableArrayUsingWeakReferencesWithCapacity:0]; } + (id)mutableArrayUsingWeakReferencesWithCapacity:(NSUInteger)capacity { … Read more