【发布时间】:2011-03-10 15:46:27
【问题描述】:
我正在尝试在一系列图像中的每一个上放置一行对话。 为了将对话行与正确的图像匹配,我以正斜杠 (/) 结束每一行,后跟一个数字来标识匹配的图像。然后我解析每一行以获取对话框,然后是图像的参考编号。 一切正常,除了当我将对话框行放入 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: @"/"];
警告:分配 'struct NSArray *' 的 Objective-C 类型不兼容,预期为 'struct NSMutableArray *'
我不太明白这一点,并试图改变类型,但无济于事。
在此不胜感激。
【问题讨论】:
-
欢迎来到 SA!提示:使用对话框按钮“代码”使您的代码看起来像代码(我以这种方式编辑了您的 q)。
-
您需要确保对类属性使用
self.访问器,例如self.dialogLineSections因为否则您没有保留管理,并且属性中的对象可能会在没有警告的情况下消失。
标签: objective-c cocoa-touch ios ipad