Я новичок в Obj-C и iPhone SDK. Тестовое приложение, с которым я работаю, представляет собой переключатель цвета, содержащий две кнопки («Назад», «Вперед») и одну текстовую метку. Идея состоит в том, чтобы переключаться между цветами радуги (фон) и циклически устанавливать соответствующую текстовую метку.
Я объявил NSArray (который должен содержать имена цветов) в RainbowViewController.h, синтезировал его в RainbowViewController.h и не могу добавить строку в этот массив.
Это файл "h":
#import <UIKit/UIKit.h>
@interface RainbowViewController : UIViewController {
IBOutlet UILabel *currentColorTextLabel;
NSArray *colorsArray;
NSString *msg;
}
@property (nonatomic, retain) IBOutlet UILabel *currentColorTextLabel;
@property (nonatomic, retain) NSArray *colorsArray;
@property (nonatomic, retain) NSString *msg;
- (IBAction) pressForwardButton;
- (IBAction) pressBackButton;
@end
Это файл "m":
#import "RainbowViewController.h"
#import <Foundation/Foundation.h>
@implementation RainbowViewController
@synthesize currentColorTextLabel;
@synthesize colorsArray;
@synthesize msg;
int currentArrayIndex = 0;
colorsArray = [[NSArray alloc] init]; //here i get "Initializer element is not constant" error message
[coloursArray addObject:@"Red"]; //here I get "Expected identifier or '(' before '[' token"
[coloursArray addObject:@"Orange"];
//etc
- (IBAction) pressForwardButton {
//here I'm going to increment currentArrayIndex, set an appropriate color, and update a currentColorTextLabel based on currentArrayIndex.
}
- (IBAction) pressBackButton {
}
//auto-genereted code here
@end