gpt4 book ai didi

objective-c - 在另一个 Viewcontroller 中标记结果

转载 作者:行者123 更新时间:2023-11-28 22:44:40 25 4
gpt4 key购买 nike

大家早上好

我有一个问题。我有一个进行计算的应用程序。如果我在同一个 ViewController 中插入标签,我会观看所有内容。

如何在另一个 View 中插入相同的标签?

这是计算的 View 。

H.

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (strong, nonatomic) IBOutlet UITextField *textField1;
@property (strong, nonatomic) IBOutlet UITextField *textField2;

@property (strong, nonatomic) IBOutlet UIButton *result;

@property (strong, nonatomic) IBOutlet UIDatePicker *data;


@end

M.

//
// ViewController.m
// IEcigarette
//
// Created by Federico on 24/11/12.
// Copyright (c) 2012 Federico. All rights reserved.
//

#import "ViewController.h"
#import "ResultViewController.h"



@interface ViewController ()
@property (strong, nonatomic) NSString * myString;

@property (strong, nonatomic) UILabel * myLabel;
@end

@implementation ViewController

-(IBAction)calculate:(id)sender{



NSDate *past = _data.date ;
NSDate *now = [NSDate date];

NSCalendar *gregorianCalendar = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSUInteger unitFlags = NSDayCalendarUnit;
NSDateComponents *components = [gregorianCalendar components:unitFlags
fromDate:past
toDate:now
options:0];
int z = [components day];
int a = ([_textField1.text intValue]);
int b = a*([_textField2.text intValue]);

int r = b * z / 20;

_myLabel.text = [[NSString alloc] initWithFormat:@"%d", r];
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (BOOL)textFieldShouldReturn:(UILabel *)myLabel {

[myLabel resignFirstResponder];

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
[self performSegueWithIdentifier:@"detail" sender:self];
}

return YES;
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"detail"]) {

ResultViewController* destVC = (ResultViewController*)segue.destinationViewController;

destVC.myString = self.myLabel.text;
destVC.navigationItem.title = self.myLabel.text;

}
}

@end

谢谢

最佳答案

为什么您也试图将相同的标签插入到另一个 View 中。只需将 label.text (string) 传递给另一个 View Controller 的字符串。然后使用该字符串并在 viewdidload 方法中使用该字符串创建一个新标签。您还可以使用 nsuserdefaults 传递值。

关于objective-c - 在另一个 Viewcontroller 中标记结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13566141/

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