私のviewcontrollerA.hには次のものがあります:
@property (nonatomic, assign) NSInteger showCommentOrCreate;
+ (PhotoViewController *) sharedManager;
viewcontrollerA.m で私は使用します:
PhotoViewController* sharedSingleton = [PhotoViewController sharedManager];
...(long)sharedSingleton.showCommentOrCreate...
+ (PhotoViewController *)sharedManager
{
static PhotoViewController *shaderManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
shaderManager = [[PhotoViewController alloc] init];
});
return shaderManager;
}
...整数の値を見つける。
viewcontrollerB では ViewcontrollerA.h をインポートし、ViewcontorllerB.m では showCommentOrCreate に値を割り当てます。
唯一の問題は、値を変更するために整数に値を2回割り当てる必要があることです。例えば:
動作しません:
-(IBAction)addAnImageForCommenting:(id)sender{
PhotoViewController* sharedSingleton = [PhotoViewController sharedManager];
sharedSingleton.showCommentOrCreate = 2;
PhotoViewController* sharedSingleton2 = [PhotoViewController sharedManager];
sharedSingleton2.showCommentOrCreate = 2;
}
動作しません:
-(IBAction)addAnImageForCommenting:(id)sender{
PhotoViewController* sharedSingleton2 = [PhotoViewController sharedManager];
sharedSingleton2.showCommentOrCreate = 2;
}
作品:
- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer {
for (UIImageView *imageView in imageArray)
{
if (([imageView isKindOfClass:[UIImageView class]] && imageView.tag == ((UITapGestureRecognizer *)gestureRecognizer).view.tag))
{
// for(UIGestureRecognizer *gesture in [imageView gestureRecognizers]){
// if([gesture isKindOfClass:[UITapGestureRecognizer class]]){
if (imageView.frame.size.height == 60){
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.27];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.frame = CGRectMake( 20, imageView.frame.origin.y, 710, 200);
[UIView commitAnimations];
[imageView setImage:[UIImage imageNamed: @"Massages retina iPad.png"]];
z = 200;
for (MKMapView* map in mapViewArray) {
if (imageView.tag == map.tag +1) {
[imageView addSubview:map];
}
}
}else {
/*[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.27];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.frame = CGRectMake( 20, imageView.frame.origin.y, 710, 60);
[UIView commitAnimations];
[imageView setImage:[UIImage imageNamed: @"message small.png"]];*/
z = 60;
for (MKMapView* map in mapViewArray) {
if (imageView.tag == map.tag +1) {
//[map removeFromSuperview];
}
}
}
} else if([imageView isKindOfClass:[UIImageView class]] && imageView.tag > ((UITapGestureRecognizer *)gestureRecognizer).view.tag){
if (z == 200){
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.27];
imageView.frame = CGRectMake( 20, imageView.frame.origin.y +150, 710, imageView.frame.size.height);
[UIView commitAnimations];
}else {
/*[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.27];
imageView.frame = CGRectMake( 20, imageView.frame.origin.y -150, 710, imageView.frame.size.height);
[UIView commitAnimations];*/
}
}}
for (UIImageView *imageView in imageArray)
{
if (([imageView isKindOfClass:[UIImageView class]] && imageView.tag == ((UISwipeGestureRecognizer *)gestureRecognizer).view.tag))
{
[UIView transitionWithView:imageView duration:0.5
options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
//imageView.image = secondImage;
} completion:^(BOOL f){
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"PhotoViewControllerStoryboard" bundle:nil];
UIViewController *vc = [sb instantiateInitialViewController];
vc.modalTransitionStyle = UIViewAnimationOptionCurveEaseIn;
vc.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:vc animated:YES];
vc.view.superview.frame = CGRectMake(15, 43, 735, 982);
PhotoViewController* sharedSingleton = [PhotoViewController sharedManager];
sharedSingleton.tagNumber = imageView.tag;
//NSLog(@"The tagNumber is: %ld", (long)sharedSingleton.tagNumber);
//sharedSingleton.showCommentOrCreate = 1;
}];
PhotoViewController* sharedSingleton = [PhotoViewController sharedManager];
sharedSingleton.tagNumber = imageView.tag;
sharedSingleton.showCommentOrCreate = [NSNumber numberWithInt:1];
}}}
ご覧のとおり、整数の値を 2 回設定すると機能しますが、それ以外の場合は機能しません。そうでない場合、時間間隔を置いてコードを2回呼び出すと、正しい値が設定されます。何か案は??
編集:動作すると主張するコードを更新しました