2013-10-11 54 views
2

我需要訪問viewController的屬性來傳遞顏色,但此屬性爲零。屬性另一個UIViewController爲空

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) 

    } 

我該怎麼辦?

+0

你在使用故事板嗎? –

+0

不,我沒有使用故事板,也沒有使用ARC –

+1

而不是'init'嘗試使用'initWithNibName' –

回答

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) 

    } 
+0

已經完成,但它不起作用 –

+0

看到我更新的答案。 – user1673099

+0

是否爲空 –

相關問題