In my UITableView I’m using custom cells with a book title, book status and renew button. However, book status requires some loading view internet and therefore takes time to load.
Have tried doing Asynchronous to load only the part on the book status but it’s too hard. Therefore, I was trying to do a “Loading Data” spinner instead. Had created a class for spinner and implemented in cellForRowAtIndexPath but the spinner only shows at the end when my UITable had already finish all the loading! I have no idea where to place this codes:
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];
}
I have already tried placing it in viewDidLoad and even viewWillAppear but it just don’t seemed to work. The results of all just ends up that the spinner shows up at the end when all things had already finish loading.
- (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;
}
In the end what I did was to place the UIActivityIndicator in the viewDidLoad method instead, and cancelled it in viewDidAppear. It works now! Thank you everyone for your help too 🙂