intialization with a nibFIle failed
Posted
by zp26
on Stack Overflow
See other posts from Stack Overflow
or by zp26
Published on 2010-05-28T22:40:40Z
Indexed on
2010/05/28
22:42 UTC
Read the original article
Hit count: 182
Hi, I have a problem. I try to initialize a variabile in a classViewController created inside a xib file. I try with the code below but when i append a object to array, these array isn't initialized. Can you help me? thanks and sorry for my english.
#import <UIKit/UIKit.h>
@interface AccelerometroViewController : UIViewController <UIAccelerometerDelegate, UITextFieldDelegate, UIAlertViewDelegate>{
//.....
NSMutableArray *arrayPosizioni;
NSMutableArray *arrayPosizioniCorrenti;
NSString *nomePosizioneCorrente;
}
-(IBAction)salvaPosizione;
//...
@property (nonatomic, assign) NSMutableArray *arrayPosizioni;
@property (nonatomic, assign) NSMutableArray *arrayPosizioniCorrenti;
@property (nonatomic, assign) NSString *nomePosizioneCorrente;
@end
#import "AccelerometroViewController.h"
#import "Position.h"
@implementation AccelerometroViewController
float actualX;
float actualY;
float actualZ;
@synthesize arrayPosition;
@synthesize arrayCurrentPosition;
@synthesize nameCurrentPosition;
-(id)init {
self = [super init];
if (self != nil) {
arrayPosition = [[NSMutableArray alloc]init];
arrayCurrentPosition = [[NSMutableArray alloc]init];
nameCurrentPosition = [NSString stringWithFormat:@"noPosition"];
actualX = 0;
actualY = 0;
actualZ = 0;
}
return self;
}
-(void)updateTextView:(NSString*)nomePosizione
{
NSString *string = [NSString stringWithFormat:@"%@", nameCurrentPosition];
textEvent.text = [textEvent.text stringByAppendingString:@"\n"];
textEvent.text = [textEvent.text stringByAppendingString:string];
}
-(IBAction)savePosition{
Posizione *newPosition;
newPosition = [[Position alloc]init];
if([newPosition setValue:(NSString*)fieldNomePosizione.text:(float)actualX:(float)actualY:(float)actualZ]){
//setValue is a method of Position. I'm sure that this method is correct
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Salvataggio Posizione" message:@"Posizione salvata con successo" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
[alert show];
[alert release];
[arrayPosition addObject:newPosition];
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Salvataggio osizione" message:@"Errore nel salvataggio" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
- (void) initialise {
arrayPosition = [[NSMutableArray alloc] init];
arrayCurrentPosition = [[NSMutableArray alloc] init];
nameCurrentPosition = @"noPosition";
actualX = 0;
actualY = 0;
actualZ = 0;
}
- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle {
if (self = [super initWithNibName:nibName bundle:bundle]) {
[self initialise];
}
}
© Stack Overflow or respective owner