我正在爲iPhone開發一個應用程序,我有一個奇怪的問題。我試圖自己解決這個問題,但3天后我仍然沒有找到解決方案。通過標籤動態查找iOS UIView
我有一個滾動視圖中,我動態創建其它視圖和子視圖,這是代碼:
for (int i=0; i<dim; i++) {
UITextView *posted_nick= [[UITextView alloc] initWithFrame:CGRectMake(paddWidth, heightUpdateImageScrollview+paddHeight/2, screenWidth-2*paddWidth, 37)];
//textview customization...
[imagesScrollView addSubview:posted_nick];
row_images_like = [[UIView alloc] initWithFrame:CGRectMake(paddWidth,heightUpdateImageScrollview+paddHeight+37+heightImageInScrollView,screenWidth-2*paddWidth,80)];
//set the tag = id
row_images_like.tag = [id_image intValue];
UIImageView *like_mini = [[UIImageView alloc] initWithFrame:CGRectMake(0,15,25,25)];
//imageview customization...
//tag = id+1..
NSInteger x = [id_image intValue] + 1;
number_like.tag = x;
[row_images_like addSubview:like_mini];
UITextView *number_like = [[UITextView alloc] initWithFrame:CGRectMake(paddWidth*5/2,10,55,37)];
//textview customization...
//tag = id+2..
NSInteger x = [id_image intValue] + 2;
number_like.tag = x;
[row_images_like addSubview:number_like];
[imagesScrollView addSubview:row_images_like];
}
現在,所有的偉大工程,當我點擊圖像視圖「like_mini」,我能找到在同一行中的其他意見與適當的標記
(UIView *thisView = (UIView*)[imagesScrollView viewWithTag:ID_IMAGE];)
問題是我更新我的滾動視圖。當用戶滾動到頂部時,如果有新圖像要顯示,我會調用創建視圖的相同函數,並將所有其他視圖(已存在的視圖)向下移動一些。爲什麼當我嘗試在我的滾動視圖中通過標籤查找視圖時,所有工作都是在第一次,但是不適用於使用相同代碼創建的新圖像?
如果我刪除滾動視圖中的所有視圖,添加新的視圖之前,它的作品。但我不想刪除最古老的視圖。
當它工作時,我有我的控制檯中的視圖(row_images_like)與標籤。 當它不起作用時,我收到一個_UITextContainerView。這是什麼?
希望我解釋一下自己。
在沒有糾正代碼和錯誤的情況下,很難將它分類。 –