0
votes

i am doing a small concept on UIscrollView . i attached 10 labels to the scrollview(languages)and i want to retrieve the label value from the label what the user have selected.this code is executing and running .but some time it is terminating with out any exception/error.

Note:i am having doubt one that is when the first time the screen appears .if i press the scrollview up button .The label in the scroll view is moving to last label.if i press the down button than it is moving first label.it is happening only for first time after that it is moving for one up/down

can any one help in solving this problem...

    -(void)printLanguage
    {
    NSLog(@"in print language method");

    //int y=0;
    //NSMutableArray *languageArray=[[NSMutableArray alloc]initWithObjects:@"Chinese",@"Spanish",@"English",@"Arabic",@"Hindi",@"Bengali",@"Portuguese",@"Russian",@"Japanese",@"German",nil];
    //UILabel *languageLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, y ,90,30 )];

    languagValue=0;

    int y=0;
    languageArray=[[NSMutableArray alloc]initWithObjects:@"Chinese",@"Spanish",@"English",@"Arabic",@"Hindi",@"Bengali",@"Portuguese",@"Russian",@"Japanese",@"German",nil]; 


    for(languagValue=0;languagValue<[languageArray count];languagValue++)
    {
        UILabel *languageLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, y ,90,30 )];
        NSLog(@"array count is @%d",[languageArray count]);
        languageLabel.text=[languageArray objectAtIndex:languagValue];
        NSLog(@"array objectat index is @%@",[languageArray objectAtIndex:languagValue]);
        languageLabel.font=[UIFont systemFontOfSize:19.0];
        languageLabel.backgroundColor=[UIColor clearColor];
        [languageScrollView addSubview:languageLabel];
        //  [languageScrollView addSubview:languageLabel];
        //y+=90;        
        y+=languageLabel.frame.size.height;
        [languageLabel release];

    }   
                            [languageScrollView setShowsHorizontalScrollIndicator:NO];
                            [languageScrollView setShowsVerticalScrollIndicator:NO];

                            [languageScrollView setContentSize:CGSizeMake(genderScrollView.frame.size.width, y)];   
         }


    -(IBAction)languageDownButton:(id)sender
    {
    NSLog(@"language scroll view  up button pressed");

    languagValue-=1;

    NSLog(@"value of language value is @%d",languagValue);
    if(!(languagValue>0))
    {
        languagValue=0; 

    }
    else if(!(languagValue<10))
    {
        languagValue=9;
    }
    else {
        NSLog(@"gender value*24 is @%d",(languagValue)*30);

         [languageScrollView setContentOffset:CGPointMake(0, (languagValue)*30) animated:YES];


    }       
}


    -(IBAction)languageUpButton:(id)sender
    {

    NSLog(@"language scroll view down button pressed");
        NSLog(@"value of language value is @%d",languagValue);
    languagValue+=1;

    if(!(languagValue>0))
    {
        languagValue=0; 

    }
    else if(!(languagValue<10))
    {
        languagValue=9;
    }
    else {
        NSLog(@"gender value*24 is @%d",(languagValue)*30);

        [languageScrollView setContentOffset:CGPointMake(0, (languagValue)*30)   animated:YES];


    }
}
1

1 Answers

0
votes

You should better use UITableView for this, with its delegate methods you can easily display your language array. and for geting the selected language,this delegate method will be used.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

see the documentation. http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html