我制作了一个Stock Tiker来显示连续的库存对象。并且对于第一个实例工作正常。
票证代码的实现如下:
- (void)viewDidLoad
{
tickerView=[[StockTiker alloc] init];
[tickerView setFrame:CGRectMake(0, 0, 320, 20)];
tickerView.delegate=self;
UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 20)];
[label setBackgroundColor:[UIColor redColor]];
label.text=@"First Object";
UILabel *label2=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 20)];
[label2 setBackgroundColor:[UIColor grayColor]];
label2.text=@"Second Object";
UILabel *label3=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 20)];
[label3 setBackgroundColor:[UIColor magentaColor]];
label3.text=@"Third Object";
UILabel *label4=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 75, 20)];
[label4 setBackgroundColor:[UIColor yellowColor]];
label4.text=@"Fourth Object";
UILabel *label5=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 75, 20)];
[label5 setBackgroundColor:[UIColor cyanColor]];
label5.text=@"Fifth Object";
viewArray=[[NSArray alloc] initWithObjects:label,label2,label3,label4,label5,nil];
[self.view addSubview:tickerView];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
#pragma mark- Ticker Delegate..
-(UIView*)viewForRow:(int)row inTicker:(StockTiker*)stock_Ticker
{
return [viewArray objectAtIndex:row];
}
-(int)numberOfRowsForStockTiker:(StockTiker*)stock_Ticker
{
return [viewArray count];
}
//输出正常
但是当我制作第二个Ticker类实例时,它彼此重叠。
使用ticker.tag
管理两个实例的输出
任何想法? 我该如何解决这个错误。 在此先感谢!
嘿我已经上传了一个例子,请检查Horizontal List
答案 0 :(得分:2)
项目here
编辑
我调查了问题并解决了重复的实例/摇摆
您的自动收报机课程使用static int count
。
静态变量每个类只实例化一次。因此 关于计数器的编码导致对象检查例如 多次。
您应该将静态变量更改为普通的ivar,并在start方法中将其实例化为0。
然后它会正常工作