我正試圖在一系列圖像上添加一行對話框。 爲了使對話線與正確的圖像相匹配,我用正斜槓(/)結尾每行,後面跟着一個數字以標識匹配的圖像。然後我解析每一行以獲取對話框,然後解析圖像的參考號。 這一切工作正常,除了當我把對話框行到一個textView我在textView而不是對話框部分整個行。 令人困惑的是控制檯似乎表明對話行的解析已經正確執行。解析字符串時出現問題
這裏是我的編碼的細節:
@interface DialogSequence_1ViewController : UIViewController {
IBOutlet UIImageView *theImage;
IBOutlet UITextView *fullDialog;
IBOutlet UITextView *selectedDialog;
IBOutlet UIButton *test_1;
IBOutlet UIButton *test_2;
IBOutlet UIButton *test_3;
NSArray *arrayLines;
IBOutlet UISlider *readingSpeed;
NSArray *cartoonViews;
NSMutableString *dialog;
NSMutableArray *dialogLineSections;
int lNum;
}
@property (retain,nonatomic) UITextView *fullDialog;
@property (retain,nonatomic) UITextView *selectedDialog;
@property (retain,nonatomic) UIButton *test_1;
@property (retain,nonatomic) UIButton *test_2;
@property (retain,nonatomic) UIButton *test_3;
@property (retain,nonatomic) NSArray *arrayLines;
@property (retain,nonatomic) NSMutableString *dialog;
@property (retain,nonatomic) NSMutableArray *dialogLineSections;
@property (retain,nonatomic) UIImageView *theImage;
@property (retain,nonatomic) UISlider *readingSpeed;
-(IBAction)start:(id)sender;
-(IBAction)counter:(id)sender;
-(IBAction)runNextLine:(id)sender;
@end
@implementation DialogSequence_1ViewController
@synthesize fullDialog;
@synthesize selectedDialog;
@synthesize test_1;
@synthesize test_2;
@synthesize test_3;
@synthesize arrayLines;
@synthesize dialog;
@synthesize theImage;
@synthesize readingSpeed;
@synthesize dialogLineSections;
-(IBAction)runNextLine:(id)sender{
//Get dialog line to display from the arrayLines array
NSMutableString *dialogLineDetails;
dialogLineDetails =[arrayLines objectAtIndex:lNum];
NSLog(@"dialogLineDetails = %@",dialogLineDetails);
//Parse the dialog line
dialogLineSections = [dialogLineDetails componentsSeparatedByString: @"/"];
selectedDialog.text =[dialogLineSections objectAtIndex: 0];
NSLog(@"Dialog part of line = %@",[dialogLineSections objectAtIndex: 0]);
NSMutableString *imageBit;
imageBit = [dialogLineSections objectAtIndex: 1];
NSLog(@"Image code = %@",imageBit);
//Select right image
int im = [imageBit intValue];
NSLog(@"imageChoiceInteger = %i",im);
//------more code
}
我上線警告:
dialogLineSections = [dialogLineDetails componentsSeparatedByString: @"/"];
警告:不兼容的Objective-C類型分配 '結構的NSArray *',預計' struct NSMutableArray *'
我不太明白這一點,並試圖改變類型,但無濟於事。
感謝您的建議。
歡迎在SA!一個提示:使用對話框按鈕「代碼」,讓你的代碼看起來像代碼(我編輯你的q。)。 – Abel 2011-03-10 15:47:49
順便提一下,控制檯讀數是: – 2011-03-10 15:50:42
您需要確保使用'self.'訪問器來獲取類屬性,例如'self.dialogLineSections'因爲否則你沒有保留管理,屬性中的對象可能會在沒有警告的情況下消失。 – TechZen 2011-03-10 16:52:39