iOS Recipes PragProgブックのレシピを使用しています。使用しているコードの元の部分は、次のとおりです。
- (void)addActivityIndicatorView {
activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityIndicatorView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleBottomMargin |
UIViewAutoresizingFlexibleLeftMargin;
CGRect aiFrame = activityIndicatorView.frame;
CGFloat originX = (self.view.bounds.size.width - aiFrame.size.width) / 2;
CGFloat originY = (self.view.bounds.size.height - aiFrame.size.height) / 2;
aiFrame.origin.x = floorl(originX);
aiFrame.origin.y = floorl(originY);
activityIndicatorView.frame = aiFrame;
[self.view addSubview:activityIndicatorView];
}
Web経由でデータをロードする他のコントロールの複数のactivityIndicatorViewsにこのactivityIndicatorコードが必要であることに気付いたので、これは再利用可能なコードを作成するための実装であり、上記のコードが1つのビューコントローラーに対して行うようにコントロールに対するactivityIndicatorビューを表示していませんはい、それを使用するコントロールごとにこのコードにステップインし、[activityIndicatorstartAnimating]を呼び出します。この関数に渡すactivityIndicatorの場合。私が求めているのは、コードの他の場所をどこで見るべきかということだと思いますか?
- (void)addActivityIndicatorView:(UIActivityIndicatorView *)acitivityIndicator toView:(UIView *)view {
acitivityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
acitivityIndicator.autoresizingMask = UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleBottomMargin |
UIViewAutoresizingFlexibleLeftMargin;
CGRect aiFrame = acitivityIndicator.frame;
CGFloat originX = (view.bounds.size.width - aiFrame.size.width) / 2;
CGFloat originY = (view.bounds.size.height - aiFrame.size.height) / 2;
aiFrame.origin.x = floorl(originX);
aiFrame.origin.y = floorl(originY);
acitivityIndicator.frame = aiFrame;
[view addSubview:acitivityIndicator];
}