2013-04-08 56 views
1

我使用隐藏的微调框和隐藏文本“加载更多”创建了自定义单元格。这些字段对于最后一个单元格是不隐藏的,这样用户可以点击它来请求更多的数据。我有这样的想法,当用户点击最后一个单元格时,微调控制器启动,但是当用户将单元格滚动出来并再次返回时,微调控制器不会显示出来。任何帮助将不胜感激:)ios:自定义单元格中的微调框在滚动后消失

我有一个是的UITableViewCell的子类自定义单元格:

@interface BrowseListCell : UITableViewCell{ 
IBOutlet UIImageView *image; 
IBOutlet UILabel *name; 
IBOutlet UILabel *loadMore; 
IBOutlet UIActivityIndicatorView *spinner; 
} 
@property(nonatomic, retain) UIImageView *image; 
@property(nonatomic, retain) UILabel *name; 
@property(nonatomic, retain) UILabel *loadMore; 
@property(nonatomic, retain) UIActivityIndicatorView *spinner; 
@end 

的tableViewController里面我有:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
//#warning Incomplete method implementation. 
// Return the number of rows in the section. 
return [_dataController countOfList]+1; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath  *)indexPath 
{ 

// Configure the cell... 
static NSString *CellIdentifier = @"BrowseListCell"; 

BrowseListCell *cell = (BrowseListCell *)[tableView  dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil]; 
    cell = [_cell autorelease]; 
    _cell = nil; 
} 
if(indexPath.row==[_dataController countOfList]){ 
    if (indexPath.row==0) { 
     cell.name.text=nil; 
     cell.image.image = nil; 
     cell.loadMore.hidden = YES; 
     return cell; 
    }else{ 
     cell.name.text=nil; 
     cell.image.image = nil; 
     cell.loadMore.hidden = NO; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     _spinner = [cell.spinner retain]; 
     _loadCell = [cell retain]; 
     return cell; 
    } 
} 
if(_dataController!=nil){ 
    BrowseProduct *productAtIndex = [_dataController objectInListAtIndex:indexPath.row]; 

    // Configure the cell... 
    if(productAtIndex!=nil){ 
     cell.name.text = productAtIndex.name; 
     cell.image.image = productAtIndex.image; 
     cell.loadMore.hidden=YES; 
    } 

} 

return cell; 

}

内didSelectRowAtIndexPath我有:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
if(indexPath.row==[_dataController countOfList]){ 
    if (indexPath.row==0) { 
     //do nothing 
    }else{ 
     NSLog(@"Loading"); 
     [_spinner startAnimating]; 
     _loadCell.userInteractionEnabled = NO; 
     NSString *startFromId = [NSString stringWithFormat:@"%d", [_dataController countOfList]]; 
     NSNotification *notification = [NSNotification notificationWithName:@"loadMore" object:startFromId]; 
     [[NSNotificationCenter defaultCenter]postNotification:notification]; 
    } 
    } 
} 
+0

加微调的,如果(细胞==零)条件 – Tendulkar 2013-04-08 04:21:29

+0

我在这是一个自定义单元格微调UITableViewCell的子类。我只是开始和停止。你的意思是在if(cell == nil)条件下启动它;我不知道增加什么手段。 – wwjdm 2013-04-08 04:24:20

+0

你可以带一个布尔变量..在did中选择set布尔变量的值是YES ..并且在索引中的行的单元格中你可以检查布尔变量值是否是然后设置spinner的属性,例如[_spinner startAnimating];否则停止....确保加载成功后,你必须设置布尔变量值是否 – Kalpesh 2013-04-08 04:59:25

回答

1

苹果的链接添加以下的的cellForRowAtIndexPath微调:

if(spinnerIsOn){ 
      [_spinner startAnimating]; 
     }else{ 
      [_spinner stopAnimating]; 
     } 

添加以下内容reloadTableViewData:

spinnerIsOn=NO; 

增加了以下到didSelectRowAtIndexPath方法:

spinnerIsOn = TRUE; 
1

添加该代码,显示即使在停止动画

spinner.hidesWhenStopped = NO; 

请到UIActivityIndicatorView

+0

是的,这将离开微调,但_loadCell.userInteractionEnabled = NO;再次变为YES。这似乎是当我滚动loadMore单元格视图时,一切都被重置。 – wwjdm 2013-04-08 23:14:45

+0

这不起作用。当我从屏幕上滚动最后一个单元格时,微调器停止。第一次当我加载tableview它停止。第二我点击微调开始的单元格。第三次将单元格从视图中移出,然后再次停止(即使未设置停止时的隐藏)。 – wwjdm 2013-04-11 06:20:07

0

您也可以继承layoutSubviews

- (void)layoutSubviews{ 
    [super layoutSubviews]; 
    [self.spinner startAnimating]; 
} 
相关问题