嘿,我需要一个似乎不起作用的if语句的帮助。
基本上我有一个显示赛车系列结果的UILabel。现在如果那轮尚未运行,结果不应该在那里,也不会显示UILabel。
我在标签中放置了一个'NA'值(不适用),并在其上运行if语句,说明该数据的结果是否等于NA,然后不打扰制作标签。但无论如何它都会使它打印出来的数据“NA”。
这是我的代码:
- (void)viewDidLoad {
// Create the scroll view for this view
scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
scrollView.contentSize = CGSizeMake(320, 220);
[scrollView setFrame:CGRectMake(0, 180, 320, 188)];
// Create all the non-changing labels
UILabel *date_title = [[UILabel alloc] initWithFrame:scrollView.bounds];
date_title.textColor = [UIColor whiteColor];
date_title.text = @"Event date:";
date_title.font = [UIFont boldSystemFontOfSize:12];
[date_title setBackgroundColor:[UIColor clearColor]];
[date_title setFrame:CGRectMake(10, 35, 100, 12)];
[scrollView addSubview:date_title];
[date_title release];
UILabel *direction_title = [[UILabel alloc] initWithFrame:scrollView.bounds];
direction_title.textColor = [UIColor whiteColor];
direction_title.text = @"Direction:";
direction_title.font = [UIFont boldSystemFontOfSize:12];
[direction_title setBackgroundColor:[UIColor clearColor]];
[direction_title setFrame:CGRectMake(10, 55, 100, 12)];
[scrollView addSubview:direction_title];
[direction_title release];
UILabel *tracklength_title = [[UILabel alloc] initWithFrame:scrollView.bounds];
tracklength_title.textColor = [UIColor whiteColor];
tracklength_title.text = @"Track Length:";
tracklength_title.font = [UIFont boldSystemFontOfSize:12];
[tracklength_title setBackgroundColor:[UIColor clearColor]];
[tracklength_title setFrame:CGRectMake(10, 75, 100, 12)];
[scrollView addSubview:tracklength_title];
[tracklength_title release];
UILabel *winner2010_title = [[UILabel alloc] initWithFrame:scrollView.bounds];
winner2010_title.textColor = [UIColor whiteColor];
winner2010_title.text = @"2010 Winners";
winner2010_title.font = [UIFont boldSystemFontOfSize:12];
[winner2010_title setBackgroundColor:[UIColor clearColor]];
[winner2010_title setFrame:CGRectMake(10, 105, 300, 12)];
[scrollView addSubview:winner2010_title];
[winner2010_title release];
winner2011_title = [[UILabel alloc] initWithFrame:scrollView.bounds];
winner2011_title.textColor = [UIColor whiteColor];
winner2011_title.font = [UIFont boldSystemFontOfSize:12];
[winner2011_title setBackgroundColor:[UIColor clearColor]];
[winner2011_title setFrame:CGRectMake(10, 160, 300, 12)];
[scrollView addSubview:winner2011_title];
[winner2011_title release];
// Do the labels for the round_name
name = [[UILabel alloc] initWithFrame:scrollView.bounds];
name.textColor = [UIColor whiteColor];
name.font = [UIFont boldSystemFontOfSize:16];
[name setBackgroundColor:[UIColor clearColor]];
[name setFrame:CGRectMake(10, 10, 280, 16)];
[scrollView addSubview:name];
[name release];
// Do the labels for the round_date
dates = [[UILabel alloc] initWithFrame:scrollView.bounds];
dates.textColor = [UIColor whiteColor];
dates.font = [UIFont systemFontOfSize:12];
[dates setBackgroundColor:[UIColor clearColor]];
[dates setFrame:CGRectMake(110, 35, 200, 12)];
[scrollView addSubview:dates];
[dates release];
// Do the labels for the round_direction
direction = [[UILabel alloc] initWithFrame:scrollView.bounds];
direction.textColor = [UIColor whiteColor];
direction.font = [UIFont systemFontOfSize:12];
[direction setBackgroundColor:[UIColor clearColor]];
[direction setFrame:CGRectMake(110, 55, 200, 12)];
[scrollView addSubview:direction];
[direction release];
// Do the labels for the round_track_length
track_length = [[UILabel alloc] initWithFrame:scrollView.bounds];
track_length.textColor = [UIColor whiteColor];
track_length.font = [UIFont systemFontOfSize:12];
[track_length setBackgroundColor:[UIColor clearColor]];
[track_length setFrame:CGRectMake(110, 75, 200, 12)];
[scrollView addSubview:track_length];
[track_length release];
// Do the labels for the 2010 winners
winner2010 = [[UILabel alloc] initWithFrame:scrollView.bounds];
winner2010.textColor = [UIColor whiteColor];
winner2010.font = [UIFont systemFontOfSize:12];
winner2010.numberOfLines = 0;
[winner2010 setBackgroundColor:[UIColor clearColor]];
[winner2010 setFrame:CGRectMake(10, 120, 300, 30)];
[scrollView addSubview:winner2010];
[winner2010 release];
// Do the labels for the 2011 winners
winner2011 = [[UILabel alloc] initWithFrame:scrollView.bounds];
winner2011.textColor = [UIColor whiteColor];
winner2011.font = [UIFont systemFontOfSize:12];
winner2011.numberOfLines = 0;
[winner2011 setBackgroundColor:[UIColor clearColor]];
[winner2011 setFrame:CGRectMake(10, 175, 300, 30)];
[scrollView addSubview:winner2011];
[winner2011 release];
// Add the content to the main scrollview
[self.view addSubview:scrollView];
[scrollView release];
}
- (void)viewDidAppear:(BOOL)animated {
if(![round_2011_winner isEqualToString:@"NA"]){
winner2011_title.text = @"2011 Winners";
winner2011.text = round_2011_winner;
}
name.text = round_name;
dates.text = round_date;
direction.text = round_direction;
track_length.text = round_track_length;
winner2010.text = round_2010_winner;
}
现在我已经设置了一个警告框来显示视图加载时的值是什么,它的值是否正确,如果它已经运行,它会显示谁赢了的值,以及它何时没有运行,它显示值NA。
这可能是因为UILabel设置为numberofline = 2吗?与角色回归有什么关系?
标签也在滚动视图中。
答案 0 :(得分:1)
尝试使用
if (![round_2011_winner isEqualToString:@"NA"]) {
...
}