Ios 每1秒重新加载UITableViewCell时,展开和折叠UITableview中的动画闪烁问题
我想在点击UITableViewCell时以动画方式展开和折叠UITableViewCell。 我的手机只有2个UILabel。我每1秒更新一个UILabel值(倒计时计时器的值显示在UILabel上,这就是为什么我每1秒更新一次UILabel值)。在1秒内连续触发NSTimer,以使闪烁发生。 如果有人知道,请给我答案 提前谢谢 我正在使用下面的代码Ios 每1秒重新加载UITableViewCell时,展开和折叠UITableview中的动画闪烁问题,ios,uitableview,animation,nstimer,expand,Ios,Uitableview,Animation,Nstimer,Expand,我想在点击UITableViewCell时以动画方式展开和折叠UITableViewCell。 我的手机只有2个UILabel。我每1秒更新一个UILabel值(倒计时计时器的值显示在UILabel上,这就是为什么我每1秒更新一次UILabel值)。在1秒内连续触发NSTimer,以使闪烁发生。 如果有人知道,请给我答案 提前谢谢 我正在使用下面的代码 - (void)startTimer { if(_timer == nil) _timer = [NSTimer sc
- (void)startTimer
{
if(_timer == nil)
_timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(currentTimerString) userInfo:nil repeats:YES];
else
[_timer fire];
}
- (void)stopTimer
{
if(_timer)
[self.timer invalidate];
self.timer = nil;
}
- (void)currentTimerString
{
self.secondsLeft -- ;
if(self.secondsLeft > 0 )
{
_hours = (int)self.secondsLeft / 3600;
_minutes = ((int)self.secondsLeft % 3600) / 60;
_seconds = ((int)self.secondsLeft %3600) % 60;
self.countTimer = [NSString stringWithFormat:@"%02d:%02d:%02d", self.hours, self.minutes, self.seconds];
NSLog(@"self.countTimer:%@",self.countTimer);
if([self.recipeTimerdelegate respondsToSelector:@selector(timerChangedInRecipe:)])
[self.recipeTimerdelegate timerChangedInRecipe:self];
}
}
- (void)timerChangedInRecipe:(RecipeTimer *)recipetimer
{
NSInteger index = recipetimer.recipeTimerId;//recipe.recipeboxId;
NSIndexPath *rowPath = [NSIndexPath indexPathForRow:index inSection:0];
[self.timerWindowTbl reloadRowsAtIndexPaths:@[rowPath] withRowAnimation:UITableViewRowAnimationNone];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
int row_height;
if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) {
row_height=expand_height;// Expanded height
}
else
{
row_height=collaps_height;
}
return row_height;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self expandCell:indexPath];
}
#pragma mark - Expand Cell
- (void)expandCell:(NSIndexPath *)indexPath
{
// self.expandedIndexPath=indexPath;
[self.tableView beginUpdates];
if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame)
{
self.expandedIndexPath = nil;
[self.tableView endUpdates];
}
else
{
self.expandedIndexPath = indexPath;
[self.tableView endUpdates];
[UIView animateWithDuration:0.7
delay:0.0
usingSpringWithDamping:1.0
initialSpringVelocity:4.0
options: UIViewAnimationOptionCurveEaseInOut
animations:^{
if([indexPath row]==((NSIndexPath*)[[self.tableView indexPathsForVisibleRows]lastObject]).row)
{
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:self.expandedIndexPath.row inSection:self.expandedIndexPath.section] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
}
}
completion:^(BOOL finished){
}];
[UIView commitAnimations];
}
}
或
或
您每1秒重新加载一次单元格,相反,我建议您访问timerChangedInRecipe中的标签,并在主线程上更新其文本(如果更新不正确)。感谢@Bharat Modi的建议,您每1秒重新加载一次单元格,相反,我建议您访问timerChangedInRecipe中的标签,并在主线程上更新其文本(如果更新不正确)。感谢您的建议@Bharat Modi,不要在所有子视图中循环,而是使用标记访问特定标签。作为UILabel*labelRecipeDesc=(UILabel)[带标记的单元格视图:1];是的,谢谢@Bharatmodi,不要在所有子视图中循环,而是使用标签访问特定标签。作为UILabel*labelRecipeDesc=(UILabel)[带标记的单元格视图:1];是的,谢谢@BharatModi
- (void)timerChangedInRecipe:(RecipeTimer *)recipetimer
{
NSInteger index = recipetimer.recipeTimerId;//recipe.recipeboxId;
NSIndexPath *rowPath = [NSIndexPath indexPathForRow:index inSection:0];
// [self.timerWindowTbl reloadRowsAtIndexPaths:@[rowPath] withRowAnimation:UITableViewRowAnimationNone];
UITableViewCell *cell = [self.timerWindowTbl cellForRowAtIndexPath:rowPath];
for(UILabel *lbl in [cell.contentView subviews])
{
if([lbl isKindOfClass:[UILabel class]])
{
if(lbl.tag == 1)
{
lbl.text=recipetimer.recipeDesc;
}
if(lbl.tag == 2)
{
lbl.text=recipetimer.countTimer;
}
}
}
}
- (void)timerChangedInRecipe:(RecipeTimer *)recipetimer
{
NSInteger index = recipetimer.recipeTimerId;//recipe.recipeboxId;
NSIndexPath *rowPath = [NSIndexPath indexPathForRow:index inSection:0];
// [self.timerWindowTbl reloadRowsAtIndexPaths:@[rowPath] withRowAnimation:UITableViewRowAnimationNone];
UITableViewCell *cell = [self.timerWindowTbl cellForRowAtIndexPath:rowPath];
UILabel *labelRecipeDesc = (UILabel*) [cell viewWithTag: 1];
labelRecipeDesc.text=recipetimer.recipeDesc;
UILabel *labelRecipeTimerCounter = (UILabel*) [cell viewWithTag: 2];
labelRecipeTimerCounter.text=recipetimer.countTimer;
}
}