1

我正在尝试显示一个在单独的类中编码的股票消息,我正在以下面的方式使用该类

当我在 xcode 中运行时,下面的代码在当前视图中显示了 iphone 模拟器中的自动收报机消息

#import "CLTickerView.h" //imported ticker message class

- (void)viewDidLoad
{
   CLTickerView *ticker = [[CLTickerView alloc] initWithFrame:CGRectMake(30, -3, 80, 40)];

   ticker.marqueeStr = @"OLD Ticker msg goes here";

   ticker.marqueeFont = [UIFont boldSystemFontOfSize:16];
   [self.view addSubview:ticker];

}

我想通过一个按钮更改股票信息和位置,我正在使用下面的代码

- (IBAction)changeTitleAndPosition:(id)sender {
{
   CLTickerView *ticker = [[CLTickerView alloc] initWithFrame:CGRectMake(10, 10, 20, 50)]; //i want to change the position here

   ticker.marqueeStr = @"NEW Ticker msg goes here"; //i want to change msg here

   ticker.marqueeFont = [UIFont boldSystemFontOfSize:16];
   [self.view addSubview:ticker];

}

但是当我点击按钮时,它每次都会创建重复的股票信息,我们是否可能只能更改信息和位置?

我知道当我单击按钮时,它每次都会创建新对象并显示重复的消息。但我不知道如何在 viewDidLoad 中初始化对象一次并从任何按钮或操作更改消息的标题和位置。

请向我建议可能的解决方案。

4

1 回答 1

0

答案很简单:只要您有对代码和活动实例的引用,您就可以更改它的属性而无需创建新实例。将 CLTickerView 声明为调用类的属性。

于 2012-04-29T17:55:42.637 回答