从UITableView1导航到UITableView2时,应显示活动指示器

War*_*ior 3 iphone objective-c uitableview activity-indicator

我想在从一个UITableView1导航到另一个UITableView2时显示一个活动指示器,并在表完全加载时停止.

我正在使用XML解析来获取UITableView2的单元格内容.

Ruc*_*hah 8

以下代码可以帮助您......

在UITableView2的.h文件中:

声明变量

UIActivityIndicatorView *progressInd;
Run Code Online (Sandbox Code Playgroud)

创造财产

@property (nonatomic, retain) UIActivityIndicatorView *progressInd;
Run Code Online (Sandbox Code Playgroud)

和声明方法

- (UIActivityIndicatorView *)progressInd;
Run Code Online (Sandbox Code Playgroud)

在UITableView2的.m文件中:

@synthesize progressInd;
Run Code Online (Sandbox Code Playgroud)

定义此方法(调整x,y,宽度,宽度位置)

- (UIActivityIndicatorView *)progressInd {
if (progressInd == nil)
{
    CGRect frame = CGRectMake(self.view.frame.size.width/2-15, self.view.frame.size.height/2-15, 30, 30);
    progressInd = [[UIActivityIndicatorView alloc] initWithFrame:frame];
    [progressInd startAnimating];
    progressInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
    [progressInd sizeToFit];
    progressInd.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
                                    UIViewAutoresizingFlexibleRightMargin |
                                    UIViewAutoresizingFlexibleTopMargin |
                                    UIViewAutoresizingFlexibleBottomMargin);

    progressInd.tag = 1;    // tag this view for later so we can remove it from recycled table cells
}
return progressInd;
}
Run Code Online (Sandbox Code Playgroud)

- (void)viewDidLoad解析开始的方法中

[self.view addSubview:self.progressInd];
Run Code Online (Sandbox Code Playgroud)

使用解析结束的后续行

[self.progressInd removeFromSuperview];
Run Code Online (Sandbox Code Playgroud)