Я создал пользовательскую ячейку со скрытым прядильником и скрытым текстом «Load More». Эти поля не отображаются для последней ячейки, чтобы пользователь мог щелкнуть ее, чтобы запросить больше данных. У меня есть это слово, так что, когда пользователь нажимает на последнюю ячейку, начинается счетчик, но когда пользователь прокручивает ячейку вне поля зрения и обратно, счетчик не отображается. Любая помощь будет оценена :)ios: Spinner в пользовательской ячейке исчезает после прокрутки
У меня есть пользовательский элемент, который является подклассом 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];
}
}
}
добавить счетчик в если (ячейки == ноль) условие – Tendulkar
У меня есть вертушку в пользовательской ячейке, которая является подкласс UITableViewCell. Я просто начинаю и останавливаюсь. Вы имеете в виду начало его в условии if (cell == nil); Я не знаю, что означает средство. – wwjdm
Вы можете взять одну логическую переменную .. В выбранном наборе значение переменной boolean равно YES .. и в ячейке для строки по индексу. Вы можете проверить, является ли значение логической переменной yes, а затем установить свойство spinner i.e [_spinner startAnimating]; в противном случае остановитесь .... убедитесь, что после загрузки успешно вам нужно установить значение переменной boolean NO – Kalpesh