ユーザーがタブを変更しているときにポップアップするalertViewがあります
UIAlertView *tempAlert = [[UIAlertView alloc] initWithTitle:@"Save Video?"
message:@"Do you wish to save the video ?"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Save",nil];
[tempAlert show];
[tempAlert setDelegate:self];
self.saveAlert = tempAlert;
[tempAlert release];
今、私はボタンクリックイベントを処理し、このイベントでは、サブビューとしてprogressViewを使用して別のアラートを表示したいと思います
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if ([alertView.title isEqualToString:@"Save Video?"])
{
if (buttonIndex == [alertView cancelButtonIndex])
{
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; //17.4.12
// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(self.saveAlert.bounds.size.width / 2, self.saveAlert.bounds.size.height - 40);
[indicator startAnimating];
[self.saveAlert addSubview:indicator];
[indicator release];
[(ImageCanvas1AppDelegate*)[[UIApplication sharedApplication] delegate] setMainAlert:self.saveAlert];
[NSThread detachNewThreadSelector:@selector(performSaveOperationWithTabChangeToIndex:) toTarget:self withObject:[NSNumber numberWithInt:self.tab]];
}
else
{
[self performSelectorOnMainThread:@selector(playMovie)
withObject:nil waitUntilDone:YES];
}
}
else
{
if (buttonIndex == [alertView cancelButtonIndex])
{
[self.videoGenerator cancelVideoGeneration];
}
}
}
ユーザーが保存ボタンに触れた場合、progressViewをサブビューとしてalertViewを表示します。このメソッドは「playMovie」メソッドで呼び出されます。
- (void)showAlert
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Generating Video"
message:@"Please wait!"
delegate:self cancelButtonTitle:@"Cancel"
otherButtonTitles:nil, nil];
[alert performSelectorOnMainThread:@selector(show)
withObject:nil
waitUntilDone:YES];
[alert setDelegate:self];
self.videoAlert = alert;
UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
[progressView setFrame:CGRectMake(alert.bounds.size.width - progressView.bounds.size.width - 95,
alert.bounds.size.height - progressView.bounds.size.height - 80,
progressView.bounds.size.width,
progressView.bounds.size.height)];
[alert addSubview:progressView];
self.progressView = progressView;
[progressView release];
[alert release];
[pool release];
}
問題は :
私がalertViewを通常表示する場合、サブビューの配置は問題ありません
しかし、alertViewを
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
progressViewの位置が不適切です