gpt4 book ai didi

iphone - 如何在 iOS 中通过函数从同一个类调用 ViewDidLoad 方法

转载 作者:行者123 更新时间:2023-11-28 20:22:10 27 4
gpt4 key购买 nike

我的第一个类是厨房课,从画廊课我将一些变量和对象传递给我的图像显示类,在我的图像显示类中有下一个图像按钮,当我按下该按钮时,我的图像中出现的所有图像显示类需要更改。

       MixViewController *mixVC = [[MixViewController alloc] init];
mixVC.readOnlyMode = YES;
mixVC.location = location;

NSArray *tree = location.gallerySerialised;
NSDictionary *galleryEntryTree = [tree objectAtIndex:tappedCoverIndex];
NSArray *sliderStates = [galleryEntryTree objectForKey:@"state"];
mixVC.infotext=[galleryEntryTree objectForKey:@"description"];
mixVC.authortext=[galleryEntryTree objectForKey:@"author"];
mixVC.tappedIndex=tappedCoverIndex;

mixVC.initialSliderStates = [NSArray arrayWithObjects:
[NSNumber numberWithInt:[[sliderStates objectAtIndex:0] intValue]],
[NSNumber numberWithInt:[[sliderStates objectAtIndex:1] intValue]],
[NSNumber numberWithInt:[[sliderStates objectAtIndex:2] intValue]],
[NSNumber numberWithInt:[[sliderStates objectAtIndex:3] intValue]],
[NSNumber numberWithInt:[[sliderStates objectAtIndex:4] intValue]],
[NSNumber numberWithInt:[[sliderStates objectAtIndex:5] intValue]],
nil];


mixVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.parentViewController presentModalViewController:mixVC animated:YES];

这是我调用 mixviewcontroller 的代码。当我按下一个按钮时,我想更改 Sliderstates 的值并重新加载 View 以根据 slider 和图库索引显示新图像。

现在我在该类的混合图像类中,当用户单击 next 而不是我调用 nextGalleryview 函数时,我想更改图像,但它不会工作

我编写这段代码通过传递相同的值来调用 self view-did-load 但它不会改变任何东西。

感谢任何帮助谢谢

   -(void)nextGalleryView
{
NSLog(@"tap index is %i",tappedIndex);
[ScrollView removeFromSuperview];
self.readOnlyMode = YES;
self.location = location;
NSArray *tree = location.gallerySerialised;
NSDictionary *galleryEntryTree = [tree objectAtIndex:tappedIndex];
NSArray *sliderStates = [galleryEntryTree objectForKey:@"state"];
self.infotext=[galleryEntryTree objectForKey:@"description"];
self.authortext=[galleryEntryTree objectForKey:@"author"];
self.tappedIndex=tappedIndex;

self.initialSliderStates = [NSArray arrayWithObjects:
[NSNumber numberWithInt:[[sliderStates objectAtIndex:0] intValue]],
[NSNumber numberWithInt:[[sliderStates objectAtIndex:1] intValue]],
[NSNumber numberWithInt:[[sliderStates objectAtIndex:2] intValue]],
[NSNumber numberWithInt:[[sliderStates objectAtIndex:3] intValue]],
[NSNumber numberWithInt:[[sliderStates objectAtIndex:4] intValue]],
[NSNumber numberWithInt:[[sliderStates objectAtIndex:5] intValue]],
nil];
[self viewDidLoad];
}

最佳答案

您需要重新设计代码。

如果您希望从 viewDidLoad 和其他方法运行相同的代码,请将这些代码从 viewDidLoad 中拉出并将其放入一个方法中,然后从 viewDidLoad 和您的方法中调用此方法。

因为显式调用 viewDidLoad 并不好。

关于iphone - 如何在 iOS 中通过函数从同一个类调用 ViewDidLoad 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15483449/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com