我需要訪問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)
}
我該怎麼辦?
你在使用故事板嗎? –
不,我沒有使用故事板,也沒有使用ARC –
而不是'init'嘗試使用'initWithNibName' –