早上好家伙,
我有个问题。我有一个进行计算的应用程序。如果我在同一个 ViewController 中插入标签,我会观看所有内容。
如何在另一个视图中插入相同的标签?
这是有计算的视图。
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
谢谢