我正在做一个关于如何向scrollview添加标签的小概念。我写了一段代码
但我的应用程序正在终止。但我无法理解为什么它会终止。可以帮助解决这个问题....我的应用程序终止插入第三个标签..
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)];
答案 0 :(得分:3)
尝试使用以下修改过的代码
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];
}