我有以下问题 - 我有一个收音机应用程序。我正在从 Web HTML 元素解析当前歌曲的标题并将其显示在标签中。我每分钟都在我的函数中使用 NSTimer 加载此元素,以查看它是否已更改。这是我的功能:
-(void)parsing
{
NSURL *url = [NSURL URLWithString:@"http://live.radioeuphoria.bg:41232/played.html?sid=1"];
NSData *webData = [NSData dataWithContentsOfURL:url];
NSString *xPathQuery = @"//tr[2]/td[2]";
TFHpple *parser = [TFHpple hppleWithHTMLData: webData];
NSArray *array = [parser searchWithXPathQuery:xPathQuery];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
CLTickerView *ticker = [[CLTickerView alloc] initWithFrame:CGRectMake(200, 798, 556, 50)]; // movable text
for (TFHppleElement *element in array)
{
ticker.marqueeStr = [[element firstChild] content];
}
// ticker.marqueeStr = @"Current song's title";
ticker.marqueeFont = [UIFont boldSystemFontOfSize:42];
[self.view addSubview:ticker];
NSLog(@"bla bla");
}
else
{
CLTickerView *ticker = [[CLTickerView alloc] initWithFrame:CGRectMake(86, 346, 230, 30)]; // movable text
for (TFHppleElement *element in array)
{
ticker.marqueeStr = [[element firstChild] content];
}
ticker.marqueeFont = [UIFont boldSystemFontOfSize:22];
[self.view addSubview:ticker];
NSLog(@"bla bla");
}
}
在我 viewDidLoad 我这样做:
- (void)viewDidLoad
{
[self parsing];
timer = [NSTimer scheduledTimerWithTimeInterval:60.0 target:self selector:@selector(parsing) userInfo:nil repeats:YES];
[super viewDidLoad];
}
这样,标签每分钟都会出现在旧标签上,而不是替换它。如何用新视图替换我正在显示的旧视图 ([self.view addSubview:ticker];)?