属性另一个UIViewController为null

时间:2013-10-11 13:18:18

标签: ios properties uiviewcontroller

我需要访问viewController的属性来传递颜色,但是这个属性是nil。

LibraryViewController.h

 #import "FinalAlgView.h"

 @interface LibraryViewController : UIViewController{
      FinalAlgView * drawView;
  }

  @property (nonatomic, retain)FinalAlgView * drawView;

TableColor.h

#import <UIKit/UIKit.h>
#import "FinalAlgView.h"
#import "LibraryViewController.h"

 @interface TableColor : UITableViewController {

 FinalAlgView *color;
 LibraryViewController * colorDraw;
}

@property (nonatomic, retain)FinalAlgView *color;

@property (nonatomic, retain)LibraryViewController * colorDraw;

 @end

在TableColor.m中

  - (void)viewDidLoad
{
   [super viewDidLoad];

    self.colorDraw =[[LibraryViewController alloc]init];
 }

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

     self.colorDraw.drawView.lineColor =[UIColor colorWithRed:255.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:0.6];
    NSLog(@"the libraryViewController is %@", self.colorDraw);
    //the libraryViewController is <LibraryViewController: 0x4d03f0>
    NSLog(@"the property is %@", self.colorDraw.drawView);
    //the property is (null)

  }

我该怎么办?

1 个答案:

答案 0 :(得分:0)

试试这个......

<强> FinalAlgView.h

@property(nonatomic,retain) UIColor *lineColor;

<强> FinalAlgView.m

@synthesize linecolor;

更新了答案2

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
        coralDraw=[LibrayViewController alloc]init];
        coralDraw.drawView=[[FinalAlgView alloc]init];
      self.coralDraw.drawView.lineColor=[[UIColor alloc]init];

     self.colorDraw.drawView.lineColor =[UIColor colorWithRed:255.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:0.6];
    NSLog(@"the libraryViewController is %@", self.colorDraw);
    //the libraryViewController is <LibraryViewController: 0x4d03f0>
    NSLog(@"the property is %@", self.colorDraw.drawView);
    //the property is (null)

  }