我有一個問題,我希望你們其中一個可以提出一個更好的方法來完成我想要做的事情。添加選中標記圖像到選中的同一行UITableView
所以我有一個UITableView的項目列表。每個tableview行都有一個「添加」按鈕。當按下添加按鈕時,所選項目被添加到主列表。 (想到一個待辦事項應用程序),這工作正常,沒有問題。我想要的是該項目被添加到列表中的某種類型的通知。例如,在添加了兩秒鐘的同一行上出現的複選標記隨即消失。這裏是我的代碼:
-(void)addToList:(id)sender event:(id)event{
//This is the add button method on each cell.
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.theTableView];
NSIndexPath *indexPath = [self.theTableView indexPathForRowAtPoint: currentTouchPosition];
//Check image is the image of the checkmark that I want to display when the user adds an item.
checkImage.alpha = 0.0f;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.7f];
checkImage.alpha = 1.0f;
checkImage.frame = CGRectMake(currentTouchPosition.x + 100, currentTouchPosition.y, 25, 25);
[UIView commitAnimations];
....[only relevant code shown]...
}
當用戶點擊添加按鈕,在checkImage淡入,並對其定位自身在用戶觸摸行+ 100個像素的權利。這可以正常工作,但不會將複選標記放置在行的中心,它可能位於中心,靠近頂部或靠近底部,具體取決於用戶點按添加按鈕的位置。我需要在中心,或以不同的方式去解決這個問題。有什麼建議麼?謝謝!
如何將'checkImage'添加到表視圖? – 2011-06-12 23:40:06
checkImage只是一個普通的UIImageView,它只是位於視圖之上,它並不是專門添加到tableview中的。 – Ryan 2011-06-12 23:47:25
用戶滾動時會發生什麼?你不會以這種方式失去你的位置嗎? – 2011-06-12 23:48:43