Ios 在appdelegate中从viewcontroller调用方法不会更改屏幕上的文本
每次启动应用程序时,我都想更改屏幕上的文本。已调用该方法,但文本不变 myAppDelegate.mIos 在appdelegate中从viewcontroller调用方法不会更改屏幕上的文本,ios,objective-c,Ios,Objective C,每次启动应用程序时,我都想更改屏幕上的文本。已调用该方法,但文本不变 myAppDelegate.m - (void)applicationDidBecomeActive:(UIApplication *)application { [[UIApplication sharedApplication] setApplicationIconBadgeNumber:-1]; viewController *object = [[viewController alloc] init]
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:-1];
viewController *object = [[viewController alloc] init];
[object methodA];
}
viewController.m
-(void)methodA{
//Create an URL pointing to your plist
NSURL *plistURL = [[NSBundle mainBundle] URLForResource: @"myPlist" withExtension: @"plist"];
//Read the plist from the application bundle into an array object.
NSArray *stringsArray = [NSArray arrayWithContentsOfURL: plistURL];
//Create a random index into the array
NSUInteger randomIndex = arc4random_uniform(stringsArray.count);
//Fetch the string at that random index
NSString *randomString = stringsArray[randomIndex];
//Set some label's text to the random string.
_myLabel.text = randomString;
NSLog(@"methodA");
}
我的日志中有“methodA”。请尝试以下代码:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
yourViewController *object = [storyboard instantiateViewControllerWithIdentifier:@"id"];
[object methodA];
将
MainStoryboard
替换为情节提要名称,将id
替换为视图控制器id。您可以在情节提要中设置id。最后用视图控制器替换您的viewController
。您正在使用情节串连板吗?您正在创建viewController
的新实例。不要那样做。获取对现有视图控制器的引用。@ArdaKeskiner是否使用情节提要?@ArdaKeskiner是否将“MainstryBoard”替换为情节提要名称?