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

标签 iphone

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

相关文章:

iphone - 无法加载从 Nib 引用的 "my-icon.png"图像 (iPhone)

iphone - 如何从 iPhone 中的 NSString 中删除空格

jquery - 使用 Mobile Safari "form assistant"更改事件不会在选定元素上触发

iphone - '支持的方向与应用程序没有共同的方向,shouldAutorotate 返回 YES'

iphone - iOS 客户端/服务器通信

直接从 appDelegate 切换选项卡时 iOS NSURLConnection 失败

iphone - iPhone应用发布后,如何排除iphone4?

iphone - 测试 iPhone 期间的背景音乐

iphone - 苹果应用程序 ID : Handing over an App ID

iphone - 动态填充 UITableView