In the function viewDidUnload it is initially empty. However, I'm following a tutorial where at the end of the function they write [super viewDidUnload]. I noticed that in the dealloc function, [super dealloc] is automatically written at the end. Why isn't it automatically written at the end of viewDidUnload? Does it make a difference? W...
I have an array initialized
- (void) viewDidLoad {
NSArray *myArray = [NSArray arrayWithObjects:
[NSArray arrayWithObjects:@"item 1-1", @"item 1-2", nil],
[NSArray arrayWithObjects:@"item 2-1", @"item 2-2", nil],
[NSArray arrayWithObjects:@"item 3-1", @"item 3-2", nil],
...
This is probably a question that is more about object alloc/retain/release, but I'll use NSString as an example. I'm aware that I can do:
NSString* myString = [[NSString alloc] initWithString:@"Test"];
to essentially allocate and initialize a string referenced by my variable myString which I should later call [myString release] upon....
I'm writing a preferences panel and I need to either update or store a password in the System.keychain for others to find. Here's the code I have so far:
Boolean addOrUpdateKey(NSString *service, NSString *key)
{
OSStatus retVal;
SecKeychainRef systemKeychainRef;
SecKeychainItemRef kcItem;
UInt32 pwSize = 0;
char *password = N...
I'm using a set of Constant.m files, one per target, to define specific things for each target. For example:
// Constants.h
extern NSString * const kDatabaseFileName;
//Constants.m
NSString * const kDatabaseFileName = @"target_one.sqlite";
I'd also like to define an NSArray for each of my targets:
NSArray * const kLabelNames = [[NSAr...
Hi All
I am attempting to replace an object in an NSMutableArray. Elsewhere in my class I am doing it successfully. Below is an example of the code failure.
NSNumber* newObject = [NSNumber numberWithDoulble:myCalculation];
NSLog(@"Old object at 12:%@",[myMisbehavingArray objectAtIndex:12];
[myMisbehavingArray replaceObjectAtIndex:12 wi...
Please look at the code below and suggest the best approach. I can't quite tell whether the code is correct. When adding objects to arrays, do they get a retain count? In the second function, am I releasing the local variable "mySubview" or the original object?
// this is a class property
myArray = [[NSMutableArray alloc] init]...
Is there a way to use NSNumberFormatter to get the 'th' 'st' 'nd' 'rd' number endings?
EDIT:
Looks like it does not exist. Here's what I'm using.
+(NSString*)ordinalNumberFormat:(NSInteger)num{
NSString *ending;
int ones = num % 10;
int tens = floor(num / 10);
tens = tens % 10;
if(tens == 1){
ending = @"th...
Is there any way to force/cajole/encourage Interface Builder into running the C preprocessor when scanning source files for IBOutlet references?
It's a tricky problem, I can see, since in an ideal world it would need to preprocess the file with the same context that the project would, ie with the precompiled headers etc (this is much mo...
I have a UILabel that shows a character count as the user types into a textfield. Currently it is sitting behind a translucent UIToolbar. I would like the UILabel to be ontop of the UIToolbar. How can I accomplish this?
...
If a BOOL has a nice short name, it's easy enough to write:
myBOOL = !myBOOL;
But what if the BOOL has a long name?
objectWithLongishName.memberWithLongishName.submember.myBOOL = !(objectWithLongishName.memberWithLongishName.submember.myBOOL);
. . . does not look so pretty.
I'm wondering if there is an easy way to toggle the BOO...
Hello,
XCode is giving me a warning that I can't figure out why.
@interface SFHFKeychainUtils : NSObject {
}
+ (BOOL) storeUsername: (NSString *) username andPassword: (NSString *) password forServiceName: (NSString *) serviceName updateExisting: (BOOL) updateExisting error: (NSError **) error;
@end
In another class I call storeUse...
Hi -
I've got an application with several modal view controllers. Most of them work fine except for one that is within a UINavigationController (so that I can show a navbar). When this modal view controller is displayed it animates fine but when dismissed it does not animate. I'd really like it to animate. Any thoughts?
Thanks much...
I'm building an iPhone app that has to download an Excel (.xls) file from a website and perform a string search of the spreadsheet data. I've done this in C#, but I have no idea how to do this in objective-c. How do I access the individual cells using objective-c?
...
I want to change the color to red.
...
What is the proper way of ending an application on the iPhone when you are finished with it?
thanks,
anton
...
I am using gesture recognizers:
Initialize in viewDidLoad:
UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
[self.view addGestureRecognizer:longPressRecognizer];
This is what longPress looks like:
- (void)longPress:(UILongPressGestureRecogni...
iPhone/Mac "play a sound class":
link text
I find an awful lot of great objective-c classes and code samples here... and elsewhere.
I successfully create the .h and .m files, but how do I call them from my existing code?
Where do I put the @class or #import statements?
How do I call the methods?
What if I need to play 2-3 different...
Is there any practical difference between the following two code snippets:
NSObject * obj = [[_mutableArrayOne objectAtIndex:i] retain];
[_mutableArrayOne removeObject:obj];
[_mutableArrayTwo addObject:obj];
[obj release];
and
NSObject * obj = [_mutableArrayOne objectAtIndex:i];
[_mutableArrayTwo addObject:obj];
[_mutableArrayOne remo...
I wonder what is wrong with this?
.h file:
typedef enum {
N4LoupeTypeRound,
N4LoupeTypeRectangle,
} N4LoupeType;
@interface N4LoupeLayer : CALayer {
N4LoupeType _type;
UIView *_originalView;
CALayer *_mask;
CALayer *_overlay;
}
@property (nonatomic) N4LoupeType type;
@property (nonatomic, assign) UIView *origi...