0
嘿,我需要幫助,似乎沒有工作的if語句。Xcode - 如果語句保持UILabel顯示
基本上我有一個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嗎?與某個角色返回什麼有關?
該標籤也位於滾動視圖內。
我已經回答了這個嘗試,不知道那裏去了......這並沒有工作,要麼很遺憾。 – fatwombat 2011-01-14 08:39:00