在我的 UITableView 中,我使用了带有书名、书状态和续订按钮的自定义单元格。但是,图书状态需要一些加载视图互联网,因此需要时间来加载。
尝试过异步加载书籍状态的部分,但这太难了。因此,我试图改用“加载数据”微调器。已经为微调器创建了一个类并在其中实现,cellForRowAtIndexPath
但微调器仅在我的 UITable 已经完成所有加载时才显示!我不知道在哪里放置这些代码:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
lVC = [[LoadingViewController alloc] initWithNibName:@"LoadingViewiPad" bundle:nil];
[self.parentViewController.view addSubview:lVC.view];
} else {
lVC = [[LoadingViewController alloc] init];
[self.parentViewController.view addSubview:lVC.view];
}
我已经尝试过将它放入其中,viewDidLoad
但viewWillAppear
它似乎不起作用。所有的结果都是当所有东西都已经完成加载时,微调器出现在最后。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UserCustomCell *cell = (UserCustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"UserCustomCell" owner:self options:nil];
cell = userCustomCell;
self.userCustomCell = nil;
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
cell.bookTitle.frame = CGRectMake(12, 0, 550, 40);
cell.renewButton.frame = CGRectMake(600, 14, 68, 24);
}
[cell.renewButton useBlackActionSheetStyle];
cell.bookTitle.text =@"Book Title";
// I place the UIActivityIndicator class here before I do the loading
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
lVC = [[LoadingViewController alloc] initWithNibName:@"LoadingViewiPad" bundle:nil];
[self.parentViewController.view addSubview:lVC.view];
} else {
lVC = [[LoadingViewController alloc] init];
[self.parentViewController.view addSubview:lVC.view];
}
NSString *reservation = [self noOfRenewalLeft:index]; ###### throw into method to do internet connection and checking
//method will then return NSString "reserved" or "notReserved"
if ([reservation isEqualToString: @"notReserved"]){ //if item not reserved
if([renewalLeftString isEqualToString: @"0"]){
cell.bookStatus.text = @"Reached Max Renewal Limit";
}
else{ //item not reserved & able to renew, therefore display renewal left
cell.bookStatus.text = [NSString stringWithFormat:@"Renewal Left: %@",renewalLeftString];
}
}
else {
cell.bookStatus.text = @"Item Reserved/On-Hold";
}
cell.renewButton.tag = index_tag;
return cell;
}