gpt4 book ai didi

iphone - 如何将值从 UIViewController 传递到 UIView?

转载 作者:行者123 更新时间:2023-12-03 21:04:03 25 4
gpt4 key购买 nike

我创建了一个 UIView 子类:

@interface GraphClass : UIView
{
NSString *str;
}

我已将 GraphClass: 分配给名为:的 UIViewController 类的 View :

@interface GraphViewController : UIViewController
{


}

现在我想从另一个 UIViewController 类传递 NSString *amount,value

@interface MonthsListController : UIViewController
{
}
in viewDIdLoad

- (void)viewDidLoad
{
GraphClass *graph = [[GraphClass alloc]init];

graph.str = @"abc";

但是如果我在 GraphClass 中打印 str 值,我会得到 NULL 值

-(void)drawRect:(CGRect)rect
{
NSLog(@"Amount is = %@",str);//NULL VAlue :(
}
}

最佳答案

MonthsListController.h

#import GraphClass.h

GraphClass *graph;

@property(nonstatic,retain)GraphClass *graph;

MonthsListController.m

@synthesis graph;

viewDidLoad

self.graph= [[GraphClass alloc]init];
[self.graph str:@"xx"];

-(void)drawRect:(CGRect)矩形

NSLog(@"%@",graph.str);

关于iphone - 如何将值从 UIViewController 传递到 UIView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9260839/

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