2011-10-31 18 views
18

Trong ứng dụng của tôi, tôi muốn thêm chỉ số hoạt động dưới UItableview nơi tableview sẽ di chuyển nhưng tôi không biết làm thế nào tôi có thể thêm chỉ số hoạt động trên đó.Làm cách nào để thêm chỉ báo hoạt động bên dưới UITableView?

Để xây dựng, khi tôi sẽ hoàn tất việc cuộn bảng xem, sau đó để có thêm dữ liệu, tôi phải đặt tùy chọn làm mới bằng chỉ báo hoạt động.

tôi đã thử nó ở trên cùng của bảng nhìn và nó đã làm việc nhưng tôi không biết làm thế nào tôi có thể thêm nó bên dưới tableview. đây là một số mã mẫu ..

 - (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]; 
} 
} 

vì vậy hãy cho tôi biết một số mã ví dụ về cách tôi có thể làm điều đó.

thực sự tôi mới phát triển ứng dụng trong iphone.Vì vậy, hãy giúp tôi.

Cảm ơn trước.

Trả lời

13

Cách tốt nhất để thêm chỉ báo hoạt động ở chân của chế độ xem bảng.

- (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; 

} 

Thêm nút vào chân trangXem và đặt nút hành động (khi cần). Cách hoạt động của tính năng xem bảng cửa hàng ứng dụng này. Khi nhấp vào nút, hãy tìm nạp thêm một số dữ liệu vào mảng bảng, cuộn bảng mà không có hoạt ảnh.

+0

nhờ tôi sẽ cố gắng mà ... – Emon

+0

: bạn sẽ cho tôi một số mã nguồn ?? – Emon

+0

bạn cần toàn bộ mã hoặc cách mã footerview – Anand

0

Một cách khác để thêm chỉ báo hoạt động. Kiểm tra xem dữ liệu của bạn có hiển thị không bằng tổng số dữ liệu hay không. Sau đó, bạn thêm một ô bổ sung và thêm nút "Xem thêm". Khi tôi nhấp vào chế độ xem, hãy ẩn nút đó và thêm chỉ báo hoạt động vào ô đó. Và khi quá trình được thực hiện, hãy tải lại chế độ xem bảng.

Cảm ơn.

49

Đây là cách tôi đã thực hiện nó:

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

Sau đó, bạn chỉ cần đặt tableFooterView để nil để xoá bỏ nó.

Lưu ý: 44, btw, là chiều cao mặc định là UITableViewCell khi sử dụng UITableViewStylePlain. Đó là 45 cho .

+0

giải pháp tuyệt vời, cảm ơn – oyatek

+0

Thiệt hại, điều này thật dễ dàng. Cảm ơn nhiều. – HotFudgeSunday

17

Swift Cập nhật: -

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

@cChathuranga Silva..Cảm ơn bạn –

Các vấn đề liên quan