2013-02-02 40 views
1

我做了一個Stock Tiker顯示連續庫存對象。併爲第一個實例罰款。UIView子類的後續實例導致顯示錯誤?

票代碼的實現如下:

- (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]]; 
    [email protected]"First Object"; 

    UILabel *label2=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 20)]; 
    [label2 setBackgroundColor:[UIColor grayColor]]; 
    [email protected]"Second Object"; 

    UILabel *label3=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 20)]; 
    [label3 setBackgroundColor:[UIColor magentaColor]]; 
    [email protected]"Third Object"; 


    UILabel *label4=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 75, 20)]; 
    [label4 setBackgroundColor:[UIColor yellowColor]]; 
    [email protected]"Fourth Object"; 

    UILabel *label5=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 75, 20)]; 
    [label5 setBackgroundColor:[UIColor cyanColor]]; 
    [email protected]"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]; 
} 

//輸出是罰款

enter image description here

但是當我做北京時間類二審它相互重疊。

輸出有兩個實例使用ticker.tag

With Two Instance

任何想法管理? 我該如何解決這個錯誤。 在此先感謝!

嘿,我已經上傳的例子,請檢查Horizontal List

+0

您沒有真正提供足夠的信息來正確調試。如果您正在創建此Ticker類的兩個實例,那麼實例化第二個實例的代碼在哪裏?這裏可能存在問題,除了可能存在的問題,即某處存在「靜態」聲明(這意味着與此類的所有實例共享此變量) –

+0

檢查上面給出的文件鏈接。此文件包含帶有靜態變量 – Warewolf

回答

2
  1. 新增objectArray2。
  2. 重複的BSE_sticker方法
  3. 在second_Sticker中做了所有相同的BSE_Sticker代碼,除了將其添加到objectArray2。
  4. 返回objectARray2基於標籤

項目here

編輯

我看着問題和解決重複實例/搖晃

你的股票類委託stkticker2使用static int count

靜態變量僅爲每個類實例化一次。因此你編碼關於計數器的 導致對象多次檢查例如 。

您應該將靜態變量更改爲正常的伊娃,並在啓動方法中將其實例化爲0。

然後它會正常工作

+0

的stockTicker文件那不是正確的答案,再次檢查沒有顯示清楚和壓倒一個。我已經在屏幕截圖 – Warewolf

+0

@Barfi上面顯示了,因爲你已經回答了,它不能正常工作。 – 2013-02-26 07:24:32

+0

現在工作,但仍然擺動。不像單身。 – 2013-02-26 07:42:42