Problem with parsing strings

Posted by Peter Small on Stack Overflow See other posts from Stack Overflow or by Peter Small
Published on 2011-03-10T15:46:27Z Indexed on 2011/03/10 16:10 UTC
Read the original article Hit count: 241

Filed under:

I am trying to put a line of dialog on each of a series of images. To match the dialog line with the correct image, I end each line with a forward slash (/) followed by a number to identify the matching image. I then parse each line to get the dialog and then the reference number for the image. It all works fine except that when I put the dialog line into a textView I get the whole line in the textView instead of the dialog part. What is confusing is that the console seems to indicate that the parsing of the dialog line has been carried out correctly.

Here are the details of my coding:

@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
}

I get a warning on the line:

dialogLineSections = [dialogLineDetails componentsSeparatedByString: @"/"];

warning: incompatible Objective-C types assigning 'struct NSArray *', expected 'struct NSMutableArray *'

I don't quite understand this and have tried to change the types but to no avail.

Would be grateful for some advice here.

© Stack Overflow or respective owner

Related posts about ipad