1

各タブが選択された後、最初のタブが読み込まれると、画面の中央に「読み込み中」インジケーターを追加しようとしています。これを達成するためのコードを示す多くの投稿を見つけましたが、webview アプリのセットアップ方法では機能しないようです。

私は初心者で、さまざまなチュートリアルからすべてのコードを作成したので、役立つコードをどこに配置するかを説明していただければ幸いです。

ここに私の現在の.hファイルがあります

 #import <UIKit/UIKit.h>

@interface ViewController1 : UIViewController

{
    IBOutlet UIWebView *myWebView;
}

@end

ここに私の現在の.mファイルがあります

#import "ViewController1.h"

@interface ViewController1 ()

@end

@implementation ViewController1


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = NSLocalizedString(@"Home", @"Home");
        self.tabBarItem.image = [UIImage imageNamed:@"birdhouse"];
    }
    return self;
}



- (void)viewDidLoad {

    [super viewDidLoad];


    {
        UIImage *navigationBarBackground = [[UIImage imageNamed:@"navbar.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

        [[UINavigationBar appearance] setBackgroundImage:navigationBarBackground forBarMetrics:UIBarMetricsDefault];

    }


    // Do any additional setup after loading the view from its nib.

    NSURL *myURL = [NSURL URLWithString:@"http://jbirdmedia.org/rcwc/iphone/home.html"];

    NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL];

    [myWebView loadRequest:myRequest];

}





- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end

失敗した試行からすべてのコードを取り出したので、このコードは現在viewcontroller1の作業アプリであり、4つのタブに4つのViewControllerがあります。

ありがとう、ジェイソン

4

2 に答える 2

0

これは非常にラフでテストされていませんが、次のようになります。

    UIView *loadingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 150)];
    loadingView.center = self.view.center;
    [loadingView setBackgroundColor:[UIColor blackColor]];
    [loadingView setAlpha:0.75f];

    UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    activityIndicator.frame = CGRectMake(0,0,40,40);
    activityIndicator.center = loadingView.center;
    [loadingView addSubview:activityIndicator];
    [activityIndicator startAnimating];

    UILabel *loadingLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 100, loadingView.bounds.size.width, 50)];
    [loadingLabel setText:@"Loading"];
    [loadingLabel setBackgroundColor:[UIColor clearColor]];
    [loadingLabel setTextAlignment:NSTextAlignmentCenter];
    [loadingLabel setTextColor:[UIColor whiteColor]];
    [loadingView addSubview:loadingLabel];

    [self.webView addSubview:loadingView];

ビューを実際に表示する方法に適応する必要がありますが、それによって正しい方向を示すことができます。

于 2012-09-26T02:59:58.623 に答える
0

あなたのコードは今、UIActivityIndi​​catorView について何も言及していません。viewDidLoad メソッドでは、次のようなものが必要です。

UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityView.center = myWebView.center;
[myWebView addSubview: activityView];
[activityView startAnimating];
于 2012-09-25T20:16:09.007 に答える