2011-10-31 12 views
18

W mojej aplikacji chcę dodać wskaźnik aktywności w widoku UItableview, w którym będzie przewijany widok tabeli, ale nie wiem, w jaki sposób mogę dodać tam wskaźnik aktywności.Jak mogę dodać wskaźnik aktywności poniżej UITableView?

Aby opracować, kiedy zakończę przewijanie tableview, a następnie dla większej ilości danych, muszę ustawić opcję odświeżania według wskaźnika aktywności.

Próbowałem go na górze tableview i działało, ale nie wiem, jak mogę dodać go poniżej tableview. Oto przykładowy kod.

 - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { 
if (isLoading) return; 
isDragging = YES; 


refreshHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, scrollView.contentOffset.y + REFRESH_HEADER_HEIGHT, 320, REFRESH_HEADER_HEIGHT)]; 
refreshHeaderView.backgroundColor = [UIColor clearColor]; 

refreshLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, scrollView.contentOffset.y + REFRESH_HEADER_HEIGHT, 320, REFRESH_HEADER_HEIGHT)]; 
refreshLabel.backgroundColor = [UIColor clearColor]; 
refreshLabel.font = [UIFont boldSystemFontOfSize:12.0]; 
refreshLabel.textAlignment = UITextAlignmentCenter; 

refreshArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"refresharrow.png"]]; 
refreshArrow.frame = CGRectMake((scrollView.contentOffset.y + REFRESH_HEADER_HEIGHT - 27)/2, 
           (scrollView.contentOffset.y + REFRESH_HEADER_HEIGHT - 44)/2, 
           27, 44); 

refreshSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
refreshSpinner.frame = CGRectMake((scrollView.contentOffset.y + REFRESH_HEADER_HEIGHT - 20)/2, (scrollView.contentOffset.y + REFRESH_HEADER_HEIGHT - 20)/2, 20, 20); 
refreshSpinner.hidesWhenStopped = YES; 

[refreshHeaderView addSubview:refreshLabel]; 
[refreshHeaderView addSubview:refreshArrow]; 
[refreshHeaderView addSubview:refreshSpinner]; 
[tableview addSubview:refreshHeaderView]; 


} 

- (void)scrollViewDidScroll:(UIScrollView *)scrollView { 
if (isLoading) { 
    // Update the content inset, good for section headers 
    if (scrollView.contentOffset.y > 0){ 
     NSLog(@"scrollView.contentOffset.y 1= %d",scrollView.contentOffset.y); 
     tableview.contentInset = UIEdgeInsetsZero; 
    } 
    else if (scrollView.contentOffset.y >= -REFRESH_HEADER_HEIGHT){ 
     NSLog(@"scrollView.contentOffset.y 2= %d",scrollView.contentOffset.y); 
     tableview.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0); 
    } 
} else if (isDragging && scrollView.contentOffset.y > scrollView.contentOffset.y + REFRESH_HEADER_HEIGHT) { 
    // Update the arrow direction and label 
    [UIView beginAnimations:nil context:NULL]; 
    if (scrollView.contentOffset.y > scrollView.contentOffset.y + REFRESH_HEADER_HEIGHT) { 
     // User is scrolling above the header 
     NSLog(@"scrollView.contentOffset.y 3= %d",scrollView.contentOffset.y); 
     refreshLabel.text = self.textRelease; 
     [refreshArrow layer].transform = CATransform3DMakeRotation(M_PI, 0, 0, 1); 
    } else { // User is scrolling somewhere within the header 
     refreshLabel.text = self.textPull; 
     [refreshArrow layer].transform = CATransform3DMakeRotation(M_PI * 2, 0, 0, 1); 
    } 
    [UIView commitAnimations]; 
} 
} 

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { 
if (isLoading) return; 
isDragging = NO; 
if (scrollView.contentOffset.y >= scrollView.contentOffset.y + REFRESH_HEADER_HEIGHT) { 
    // Released above the header 
    [self startLoading]; 
} 
} 

, więc proszę, daj mi przykładowy kod o tym, jak mogę to zrobić.

w rzeczywistości jestem nowy w rozwoju aplikacji iPhone. Więc proszę, pomóż mi.

Dzięki z góry.

Odpowiedz

13

Najlepszym sposobem dodania wskaźnika aktywności jest stopka widoku tabeli.

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { 
UIView *headerView = [[[UIView alloc] init]autorelease]; 

    [headerView setBackgroundColor:[UIColor clearColor]]; 

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button addTarget:self 
           action:@selector(aMethod:) 
 forControlEvents:UIControlEventTouchDown]; 
[button setTitle:@"Load More" forState:UIControlStateNormal]; 
button.frame = CGRectMake(10.0, 210.0, 160.0, 40.0); 


    [headerView addSubview:button]; 

    [headerLabel release]; 

    return headerView; 

} 

Dodaj przycisk do footerView i ustaw akcję na przycisk (zgodnie z potrzebą). W ten sposób działa widok tabeli przechowywania aplikacji. Po kliknięciu przycisku pobierz więcej danych dodaj do tablicy tabeli przewiń tabelę bez animacji.

+0

dzięki postaram że ... – Emon

+0

: dasz mi trochę kodu źródłowego ?? – Emon

+0

potrzebujesz całego kodu lub kodu footerview – Anand

0

Kolejny sposób na dodanie wskaźnika aktywności. Sprawdź, czy wyświetlane dane nie są równe całkowitej liczbie danych. Następnie dodajesz jedną dodatkową komórkę i dodajesz przycisk "Zobacz więcej". Kiedy klikam w widok bardziej, ukryj ten przycisk i dodaj wskaźnik aktywności w tej komórce. A kiedy proces się zakończy, ponownie załaduj widok tabeli.

Dzięki.

49

ten sposób robiłem go:

UIActivityIndicatorView *spinner = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease]; 
[spinner startAnimating]; 
spinner.frame = CGRectMake(0, 0, 320, 44); 
self.tableView.tableFooterView = spinner; 

Następnie wystarczy ustawić tableFooterView do nil, aby ją usunąć.

Uwaga: 44, przy okazji, domyślna wysokość to UITableViewCell przy użyciu UITableViewStylePlain. To 45 dla .

+0

świetne rozwiązanie, dzięki – oyatek

+0

Cholera, to było łatwe. Wielkie dzięki. – HotFudgeSunday

17

Swift Aktualizacja: -

let pagingSpinner = UIActivityIndicatorView(activityIndicatorStyle: .Gray) 
pagingSpinner.startAnimating() 
pagingSpinner.color = UIColor(red: 22.0/255.0, green: 106.0/255.0, blue: 176.0/255.0, alpha: 1.0) 
pagingSpinner.hidesWhenStopped = true 
tableView.tableFooterView = pagingSpinner 
+0

@Chathuranga Silva..Thank u –

Powiązane problemy