1

I made a Stock Tiker to display continuous stock objects. And Working fine for first Instance.

The implementation of the ticket code is as follows:

- (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];
}

//Output is fine

enter image description here

But when I made second Instance of Ticker class it overlapped to each other.

Output with two instance managed using ticker.tag

With Two Instance

Any Idea? How can I solve this error. Thanks in Advance!

Hey I have uploaded an example please check it Horizontal List

Prince Kumar Sharma
  • 12,591
  • 4
  • 59
  • 90
  • You have not really supplied enough info to debug this properly. If you are creating two instances of this Ticker class, then where is the code where you instantiate the second instance? There is likely a problem there, besides the likely issue that you have a 'Static' declaration somewhere (which means share this variable with ALL instances of this class) – G. Shearer Feb 26 '13 at 21:35
  • check the file link,given above.this contains stockTicker file with static variable – Prince Kumar Sharma Feb 27 '13 at 05:29

1 Answers1

2
  1. Added objectArray2.
  2. Duplicated BSE_sticker method
  3. in second_Sticker did all the same code of BSE_Sticker except add it to objectArray2.
  4. Return objectARray2 for stkticker2 in delegate based on tag

Project here

Edit

I looked into issue and solved repeating instance/ wobbling

Your ticker class uses static int count.

Static variables are instantiated only once per class. and therefore you coding regarding counter leads the object to check for instance multiple times.

you should change the static variable to a normal ivar and instantiate it to 0 in start method.

Then it will work fine

Shubhank
  • 21,721
  • 8
  • 65
  • 83