Ios 为什么赢了';t将我的文本显示从ViewController上切换到下一个
我试图传递字符串属性,我必须设置标签的文本。但是,该字符串不会显示。我正在浏览多个视图控制器。其思想是从文本字段中获取信息,然后将其存储到属性中。然后在以后的视图控制器中将标签设置为字符串属性Ios 为什么赢了';t将我的文本显示从ViewController上切换到下一个,ios,objective-c,uitextfield,uilabel,Ios,Objective C,Uitextfield,Uilabel,我试图传递字符串属性,我必须设置标签的文本。但是,该字符串不会显示。我正在浏览多个视图控制器。其思想是从文本字段中获取信息,然后将其存储到属性中。然后在以后的视图控制器中将标签设置为字符串属性 SentenceViewContoller.m #import "SentenceViewController.h" #import "DrawViewController.h" @interface SentenceViewController () @end
SentenceViewContoller.m
#import "SentenceViewController.h"
#import "DrawViewController.h"
@interface SentenceViewController ()
@end
@implementation SentenceViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.Sentence1TF.text = self.Sent1Str;
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
}
- (IBAction)stopped:(id)sender {
}
@end
-----------------------------------------------------------------------
SentenceViewController.m
#import "SentenceViewController.h"
#import "DrawViewController.h"
@interface SentenceViewController ()
@end
@implementation SentenceViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.Sentence1TF.text = self.Sent1Str;
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
}
- (IBAction)stopped:(id)sender {
}
@end
------------------------------------------------------------------------------
DrawViewController.h
#import <UIKit/UIKit.h>
@interface DrawViewController : UIViewController {
CGPoint lastPoint;
CGFloat red;
CGFloat green;
CGFloat blue;
CGFloat brush;
CGFloat opacity;
BOOL mouseSwiped;
}
@property (strong, nonatomic) IBOutlet UIImageView *tempDrawImage;
@property (strong, nonatomic) IBOutlet UIImageView *mainImage;
- (IBAction)pencilPressed:(id)sender;
- (IBAction)eraserPressed:(id)sender;
@property (weak, nonatomic) IBOutlet UILabel *Sentence1;
@property (weak, nonatomic) IBOutlet UIButton *Done;
@property (nonatomic, retain) NSString *Sent1Str;
@end
------------------------------------------------------------------------
DrawViewController.m
#import "DrawViewController.h"
#import "Draw2ViewController.h"
#import "SentenceViewController.h"
@interface DrawViewController ()
@end
@implementation DrawViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
red = 0.0/255.0;
green = 0.0/255.0;
blue = 0.0/255.0;
brush = 10.0;
opacity = 1.0;
[super viewDidLoad];
//Do any additional setup after loading the view.
self.Sent1Str = ((SentenceViewController *)self.parentViewController).Sent1Str;
Draw2ViewController *D2V = [[Draw2ViewController alloc] init];
D2V.myImage = _mainImage;
self.Sentence1.text = self.Sent1Str;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)pencilPressed:(id)sender {
UIButton * PressedButton = (UIButton*)sender;
switch(PressedButton.tag)
{
case 0:
red = 0.0/255.0;
green = 0.0/255.0;
blue = 0.0/255.0;
break;
case 1:
red = 105.0/255.0;
green = 105.0/255.0;
blue = 105.0/255.0;
break;
case 2:
red = 255.0/255.0;
green = 0.0/255.0;
blue = 0.0/255.0;
break;
case 3:
red = 0.0/255.0;
green = 0.0/255.0;
blue = 255.0/255.0;
break;
case 4:
red = 102.0/255.0;
green = 204.0/255.0;
blue = 0.0/255.0;
break;
case 5:
red = 102.0/255.0;
green = 255.0/255.0;
blue = 0.0/255.0;
break;
case 6:
red = 51.0/255.0;
green = 204.0/255.0;
blue = 255.0/255.0;
break;
case 7:
red = 160.0/255.0;
green = 82.0/255.0;
blue = 45.0/255.0;
break;
case 8:
red = 255.0/255.0;
green = 102.0/255.0;
blue = 0.0/255.0;
break;
case 9:
red = 255.0/255.0;
green = 255.0/255.0;
blue = 0.0/255.0;
break;
}
}
- (IBAction)eraserPressed:(id)sender {
red = 255.0/255.0;
green = 255.0/255.0;
blue = 255.0/255.0;
opacity = 1.0;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = NO;
UITouch *touch = [touches anyObject];
lastPoint = [touch locationInView:self.view];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = YES;
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];
UIGraphicsBeginImageContext(self.view.frame.size);
[self.tempDrawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), brush );
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, 1.0);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeNormal);
CGContextStrokePath(UIGraphicsGetCurrentContext());
self.tempDrawImage.image = UIGraphicsGetImageFromCurrentImageContext();
[self.tempDrawImage setAlpha:opacity];
UIGraphicsEndImageContext();
lastPoint = currentPoint;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if(!mouseSwiped) {
UIGraphicsBeginImageContext(self.view.frame.size);
[self.tempDrawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), brush);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, opacity);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());
self.tempDrawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
UIGraphicsBeginImageContext(self.mainImage.frame.size);
[self.mainImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) blendMode:kCGBlendModeNormal alpha:1.0];
[self.tempDrawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) blendMode:kCGBlendModeNormal alpha:opacity];
self.mainImage.image = UIGraphicsGetImageFromCurrentImageContext();
self.tempDrawImage.image = nil;
UIGraphicsEndImageContext();
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
}
@end
-------------------------------------------------------------------------
Draw2ViewController.h
#import <UIKit/UIKit.h>
#import "DrawViewController.h"
#import "ResultsViewController.h"
@interface Draw2ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *Draw2Image;
@property (nonatomic, strong) UIImage *myImage;
@property (weak, nonatomic) IBOutlet UITextField *Sentence2TF;
- (IBAction)stopped2:(id)sender;
@property (nonatomic, retain) NSString *Sent1Str;
@property (nonatomic, retain) NSString *Sent2Str;
@end
------------------------------------------------------------------------
Draw2ViewController.m
#import "Draw2ViewController.h"
#import "DrawViewController.h"
#import "ResultsViewController.h"
@interface Draw2ViewController ()
@end
@implementation Draw2ViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_Sentence2TF.text = _Sent2Str;
self.Sent1Str = ((DrawViewController *)self.parentViewController).Sent1Str;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
}
- (IBAction)stopped2:(id)sender {
}
@end
---------------------------------------------------------------------------
ResultsViewController.h
#import <UIKit/UIKit.h>
@interface ResultsViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *ResultsImage;
@property (weak, nonatomic) IBOutlet UILabel *Sent1Results;
@property (weak, nonatomic) IBOutlet UILabel *Sent2Results;
@property (nonatomic, retain) NSString *Sent2Str;
@property (nonatomic, retain) NSString *Sent1Str;
@end
-----------------------------------------------------------------------------
ResultsViewController.m
#import "ResultsViewController.h"
#import "Draw2ViewController.h"
@interface ResultsViewController ()
@end
@implementation ResultsViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.Sent1Str = ((Draw2ViewController *)self.parentViewController).Sent1Str;
self.Sent2Str = ((Draw2ViewController *)self.parentViewController).Sent2Str;
_Sent1Results.text = _Sent1Str;
_Sent2Results.text = _Sent2Str;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
SentenceViewContoller.m
#导入“SentenceViewController.h”
#导入“DrawViewController.h”
@接口语句ViewController()
@结束
@实现语句视图控制器
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
//自定义初始化
}
回归自我;
}
-(无效)viewDidLoad
{
[超级视图下载];
self.Sentence1TF.text=self.Sent1Str;
//加载视图后执行任何其他设置。
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
-(void)prepareForSegue:(UIStoryboardSegue*)segue发送方:(id)发送方
{
}
-(iAction)已停止:(id)发送方{
}
@结束
-----------------------------------------------------------------------
SentenceViewController.m
#导入“SentenceViewController.h”
#导入“DrawViewController.h”
@接口语句ViewController()
@结束
@实现语句视图控制器
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
//自定义初始化
}
回归自我;
}
-(无效)viewDidLoad
{
[超级视图下载];
self.Sentence1TF.text=self.Sent1Str;
//加载视图后执行任何其他设置。
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
-(void)prepareForSegue:(UIStoryboardSegue*)segue发送方:(id)发送方
{
}
-(iAction)已停止:(id)发送方{
}
@结束
------------------------------------------------------------------------------
DrawViewController.h
#进口
@接口DrawViewController:UIViewController{
CGPoint-lastPoint;
cg-浮红;
绿色;
CGFloat蓝;
CG浮子刷;
CGFloat不透明度;
布尔老鼠;
}
@属性(强,非原子)IBUIImageView*tempDrawImage;
@属性(强,非原子)IBUIImageView*mainImage;
-(i动作)铅笔按下:(id)发送者;
-(iAction)已擦除:(id)发送方;
@性质(弱,非原子)IBUILabel*语句1;
@属性(弱,非原子)IBUIButton*完成;
@属性(非原子,保留)NSString*Sent1Str;
@结束
------------------------------------------------------------------------
DrawViewController.m
#导入“DrawViewController.h”
#导入“Draw2ViewController.h”
#导入“SentenceViewController.h”
@接口DrawViewController()
@结束
@DrawViewController的实现
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
//自定义初始化
}
回归自我;
}
-(无效)viewDidLoad
{
红色=0.0/255.0;
绿色=0.0/255.0;
蓝色=0.0/255.0;
刷子=10.0;
不透明度=1.0;
[超级视图下载];
//加载视图后执行任何其他设置。
self.Sent1Str=((SentenceViewController*)self.parentViewController).Sent1Str;
Draw2ViewController*D2V=[[Draw2ViewController alloc]init];
D2V.myImage=\u main image;
self.Sentence1.text=self.Sent1Str;
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
-(iAction)铅笔按下:(id)发送者{
UIButton*按下按钮=(UIButton*)发送器;
开关(按下按钮。标签)
{
案例0:
红色=0.0/255.0;
绿色=0.0/255.0;
蓝色=0.0/255.0;
打破
案例1:
红色=105.0/255.0;
绿色=105.0/255.0;
蓝色=105.0/255.0;
打破
案例2:
红色=255.0/255.0;
绿色=0.0/255.0;
蓝色=0.0/255.0;
打破
案例3:
红色=0.0/255.0;
绿色=0.0/255.0;
蓝色=255.0/255.0;
打破
案例4:
红色=102.0/255.0;
绿色=204.0/255.0;
蓝色=0.0/255.0;
打破
案例5:
红色=102.0/255.0;
绿色=255.0/255.0;
蓝色=0.0/255.0;
打破
案例6:
红色=51.0/255.0;
绿色=204.0/255.0;
蓝色=255.0/255.0;
打破
案例7:
红色=160.0/255.0;
绿色=82.0/255.0;
蓝色=45.0/255.0;
打破
案例8:
红色=255.0/255.0;
绿色=102.0/255.0;
蓝色=0.0/255.0;
打破
案例9:
红色=255.0/255.0;
绿色=255.0/255.0;
蓝色=0.0/255.0;
打破
}
}
-(iAction)已擦除:(id)发送方{
红色=255.0/255.0;
绿色=255.0/255.0;
蓝色=255.0/255.0;
不透明度=1.0;
}
-(无效)接触