伙计们已经开了好几个小时.... :(
我有一个加载到scrollview
的控制器数组我想将值分配给Label'Category',但我无法执行此操作 - 该值显示为NULL ??
但我可以在方法viewDidLoad中对此进行硬编码?
我尝试了几种方法,但都没有用? ...
我的.h文件看起来像这样......
@interface ReviewCategoryViewController : UIViewController {
@public
UILabel *CategoryTitle;
}
- (id)initWithCategory:(NSString *)category;
- (id)setCategory:(NSString *)category;
@property (strong, nonatomic) IBOutlet UILabel *CategoryTitle;
@end
我的实现看起来像这样......
- (id)setCategory:(NSString *)category
{
[self.CategoryTitle setText:category];
NSLog(@">>2. Category %@ %@", category, CategoryTitle.text);
return self;
}
// load the view nib and initialize the pageNumber ivar
- (id)initWithCategory:(NSString *)category
{
self = [super initWithNibName:@"ReviewCategoryViewController" bundle:nil];
[self.CategoryTitle setText:category];
NSLog(@">>1. Category %@ %@", category, CategoryTitle.text);
return self;
}
我对该方法的调用看起来像这样......
ReviewCategoryViewController *controller = [viewControllers objectAtIndex:cardNo];
if ((NSNull *)controller == [NSNull null])
{
NSString *temp = [categories_array objectAtIndex:cardNo];
controller = [[ReviewCategoryViewController alloc] initWithCategory:temp];
[controller setCategory:temp];
[viewControllers replaceObjectAtIndex:cardNo withObject:controller];
}
我的日志显示以下内容????
2013-04-12 16:54:27.507 Review Writer[14455:11603] >>1. Category Adapability **(null)**
2013-04-12 16:54:27.509 Review Writer[14455:11603] >>2. Category Adapability **(null)**
答案 0 :(得分:0)
- (id)initWithCategory:(NSString *)category
{
seidlf = [super initWithNibName:@"ReviewCategoryViewController" bundle:nil];
[self.CategoryTitle setText:category];
NSLog(@">>1. Category %@ %@", category, CategoryTitle.text);
return self;
}
致电self = [super initWithNibName:@"ReviewCategoryViewController" bundle:nil];
后,您的商店的链接尚未建立。您只能在viewDidLoad
方法
答案 1 :(得分:0)
您可以在全局变量中设置类别,并在didLoad方法中设置标签文本:
- (id)initWithCategory:(NSString *)category
{
self = [super initWithNibName:@"ReviewCategoryViewController" bundle:nil];
// categoryStr is a global NSString var
categoryStr = category;
return self;
}
- (void)viewDidLoad
{
[self.CategoryTitle setText:categoryStr];
}