Reputation: 900
i am doing a small on concept on how to add label to scrollview . I have written a code
but my app is terminating .but i can't understand it why it is terminating .can any one help in solving this problem....my application is terminating at inserting at third label..
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 )];
for(int i=0;i<[languageArray count];i++)
{
NSLog(@"array count is @%d",[languageArray count]);
languageLabel.text=[languageArray objectAtIndex:i];
NSLog(@"array objectat index is @%@",[languageArray objectAtIndex:i]);
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)];
Upvotes: 1
Views: 2652
Reputation: 31722
Try with below modified code
int y=0;
NSMutableArray *languageArray=[[NSMutableArray alloc]initWithObjects:@"Chinese",@"Spanish",@"English",@"Arabic",@"Hindi",@"Bengali",@"Portuguese",@"Russian",@"Japanese",@"German",nil];
for(int i=0;i<[languageArray count];i++)
{
UILabel *languageLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, y ,90,30 )];
NSLog(@"array count is @%d",[languageArray count]);
languageLabel.text=[languageArray objectAtIndex:i];
NSLog(@"array objectat index is @%@",[languageArray objectAtIndex:i]);
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];
}
Upvotes: 3