我创建了一个 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/