테이블 뷰에 일부 데이터를로드해야하는데이 백그라운드에서 진행되는 동안 진행 상태가 있음을 보여주기 위해 작업 표시기를 추가하려고합니다. 끝내라. 이와 같은 것을 구현하는 가장 효율적인 방법은 무엇입니까?UITableView에 UIActivityIndicator 추가하기
0
A
답변
1
사용자를 차단할지 여부와 활동 표시의 중요도에 따라 다릅니다.
당신은 당신이 더 큰 활동 표시를 갖고 싶어하고 여전히 사용자를 차단 테이블 뷰 (tableview.height -= activityview.height
) 아래의 텍스트와 UIActivityIndicator와 UIView의 애니메이션을하지 않을 경우, Application.networkActivityIndicatorVisible
를 사용하여 사용자를 차단하려면 다음 전체에 숨길 수없는 경우 또는 사용자를 차단하려면 차단 활동 표시기를 사용하십시오.
-
는 (개인적으로 MBProgressHUD를 사용했고 그것은 배우고 사용하기 쉽습니다)
0
당신은 셀의 하위 뷰 같은 UIIndicatorView와 UILabel의가있는 뷰를 추가 할 수 있습니다. 당신은 ... 오류 데이터 로딩/오류 네트워크/빈 데이터를 표시하려면이 방법을 사용할 수 있습니다
예 : UITableViewModeMessage 및 UITableViewModeData : 두 가지 모드를 정의 할 수 있습니다
컨트롤러.
viewDidLoad에서 self.tableViewMode = UITableViewModeMessage를 설정합니다. 데이터가 반환되면 self.tableViewMode = UITableViewModeData를 설정하고 tableview에 대한 데이터를 다시로드하십시오.
일부 코드 :
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (self.tableViewMode == UITableViewModeMessage) {
return 2;
} else {
return self.yourEntries ? self.yourEntries.count : 0;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.tableViewMode == UITableViewModeMessage) {
return [self tableView:tableView messageCellForRowAtIndexPath:indexPath];
} else {
return [self tableView:tableView dataCellForRowAtIndexPath:indexPath];
}
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// Remove Loading... progress view if exist.
UIView *progressView = [cell viewWithTag:100];
[progressView removeFromSuperview];
if (self.tableViewMode == UITableViewModeMessage) {
if (indexPath.row == 1) {
// remove the current label.
cell.textLabel.text = nil;
// We build progress view and attach to cell here but not in cellForRowAtIndexPath is because in this method cell frame is already calculated.
UIView *progressView = [self progressViewForCell:cell message:@"Loading..." alpha:0.9];
[cell addSubview:progressView];
}
}
}
// cell to display when loading
- (UITableViewCell *)tableView:(UITableView *)tableView messageCellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MessageCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.textLabel.textColor = [UIColor grayColor];
cell.textLabel.textAlignment = UITextAlignmentCenter;
}
if (indexPath.row == 1) {
cell.textLabel.text = @"Loading...";
} else {
cell.textLabel.text = nil;
}
return cell;
}
// cell to display when has data
- (UITableViewCell *)tableView:(UITableView *)tableView dataCellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"DataCell";
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [[self.yourEntries objectAtIndex:indexPath.row] description];
return cell;
}
// Build a view which has a UIActivityIndicatorView and a UILabel
- (UIView *)progressViewForCell:(UITableViewCell *)cell message:(NSString *)message alpha:(CGFloat)alpha
{
// NOTE: progressView needs to be removed from cell in cellForRowAtIndexPath:
CGRect progressViewFrame = CGRectZero;
progressViewFrame.size.width = CGRectGetMaxX(cell.bounds);
progressViewFrame.size.height = CGRectGetMaxY(cell.bounds) - 2;
UIView *progressView = [[UIView alloc] initWithFrame:progressViewFrame];
progressView.backgroundColor = RGBA(255, 255, 255, 1);
progressView.alpha = alpha;
progressView.tag = 100;
UILabel *loadingLabel = [[UILabel alloc] initWithFrame:progressView.bounds];
loadingLabel.backgroundColor = [UIColor clearColor];
loadingLabel.font = [UIFont systemFontOfSize:14];
loadingLabel.textColor = [UIColor blackColor];
loadingLabel.textAlignment = UITextAlignmentCenter;
loadingLabel.text = message;
CGFloat widthOfText = [loadingLabel.text sizeWithFont:loadingLabel.font].width;
CGFloat spaceBetweenIndicatorAndLabel = 5;
// activityIndicatorView has size in which width and height is equal to 20.
UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[activityIndicatorView setCenter:CGPointMake(CGRectGetMidX(cell.bounds) - (widthOfText/2) - (activityIndicatorView.bounds.size.width/2) - spaceBetweenIndicatorAndLabel, CGRectGetMidY(cell.bounds))];
[activityIndicatorView setColor:[UIColor blackColor]];
[activityIndicatorView startAnimating];
[progressView addSubview:activityIndicatorView];
[progressView addSubview:loadingLabel];
return progressView;
}
관련 문제
- 1. 동적으로 데이터를 UITableView에 추가하기
- 2. 섹션을 UITableView에 추가하기
- 3. UITableView에 그림자 추가하기
- 4. iOS 배열을 사용하여 UITableView에 추가하기
- 5. iOS : NSXMLParser - 속성 값을 UITableView에 추가하기
- 6. UIView 클래스가 아닌 UIActivityIndicator
- 7. 새 항목을 추가하기 위해 UITableView에 행을 추가 하시겠습니까?
- 8. UITableView에 데이터/행 추가하기 (하나의보기에서 여러 테이블 사용)
- 9. x 초 동안 UIActivityIndicator 표시
- 10. UIActivityIndicator 온라인에서 이미지를로드 할 때보기?
- 11. 는 UIActivityIndicator 라이브 비디오 (.mjpg)
- 12. UIActivityIndicator 문제 - 때때로 멈추지 않습니다.
- 13. Quartz 드로잉 작업 중 UIActivityIndicator
- 14. 애니메이션으로 UITableView에 삽입 하시겠습니까?
- 15. iOS 6 및 UIAavigationBar의 UIActivityIndicator 문제 titleView
- 16. SYNCHRONOUS 다운로드를 수행하는 동안 UIActivityIndicator 표시
- 17. 프로세스 실행 후 UIActivityIndicator 시작 루프
- 18. URL에서 다운로드 할 때 UIActivityIndicator 문제가 발생합니다.
- 19. 이전 iOS 버전에서 UIActivityIndicator 색상이 충돌 함
- 20. tableviewcell의 UIActivityIndicator Detailsview를로드 할 때 늦게 표시됩니까?
- 21. UIScrollView의 UITableView에 대한 자습서 또는 샘플 코드
- 22. ios에서 번들에 값 추가하기
- 23. UITableView에 "자세히보기"추가
- 24. UItableView에 이미지 추가
- 25. UITableView에 의견 달기
- 26. UITableView에 새 섹션 삽입
- 27. RSS 피드가 UITableView에 느리게로드됩니다.
- 28. UITableView에 UIActivityIndicator를 추가하십시오.
- 29. 연락처를 UItableview에 표시
- 30. uitableview에 tabbar를 추가하는 방법
나는 확실히 그 링크를 좋아합니다. 제게 이것들을 보여 줘서 고마워요. –
그런데 어떻게 MBProgressHud 프로젝트를 앱에 추가 했습니까? 컴파일 할 때마다 컴파일 오류가 발생합니다. –
어떤 종류의 컴파일 오류입니까? ARC를 사용하고 있다면, MBProgressHUD ('Target'>'Build Phases'>'Compilation Sources'>'MBProgressHUD.m' 컴파일러 플래그'-fno-objc-arc')에 대해 ARC를 비활성화해야합니다. –