我有以下情况。我有一个视图控制器(ContentController),顶部有3个按钮。下面我添加了第二个视图(contentView),这个视图应该显示这3个按钮后面的内容。所以每次按下按钮时,contentView都会改变。所以我做了三个加法控制器。无法在视图中设置标签
FirstController.m,FirstController.h,FirstController.xib
SecondController.m,SecondController.h,SecondController.xib,
ThirdController.m,ThirdController.h,ThirdController.xib,
在我的ContentController.m我添加了3个IBAction来处理这个改变。
@interface ViewController()
@property (nonatomic,strong) UIViewController *nextController;
@end
@implementation ViewController
@synthesize nextController = _nextController;
-(IBAction)chooseFirstController:(id)sender {
_nextController = [[FirstController alloc] initWithNibName:@"FirstController" bundle:nil];
[self.contentView addSubview:_nextController.view];
}
-(IBAction)chooseSecondController:(id)sender{
_nextController = [[SecondController alloc] initWithNibName:@"SecondController" bundle:nil];
[self.contentView addSubview:_nextController.view];
}
-(IBAction)chooseThirdController:(id)sender{
_nextController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
[self.contentView addSubview:_nextController.view];
}
我的第一个和ThirdController只是在contentController的contentView中显示tableviews。但在我的第二控制器中,我使用了一个gridView来显示项目。现在,当我按下一个单元格时,它应该转到detailViewController,它会显示有关该单元格的更多信息。所以在我的cellForRowAtIndex我做了以下。
- (void)gridView:(NRGridView *)gridView didSelectCellAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"cell clicked");
PlayerDetailController *playerController = [[PlayerDetailController alloc]initWithNibName:@"PlayerDetailController" bundle:nil];
[playerController setLblTest:@"hooray this works"];
[self.view addSubview:playerController.view];
}
它正确执行setLblTest并在我的ContentView中显示detailViewcontroller。但它不会更改标签。到我的@“hooray”这个作品。但是,尽管你可以在我的日志中看到它正确传递它。
@synthesize testLabel = _testLabel;
@synthesize lblTest = _lblTest;
-(void)setLblTest:(NSString *)lblTest{
if(![_lblTest isEqual:lblTest]){
_lblTest = lblTest;
}
NSLog(@"log komt %@",lblTest);
[_testLabel setText:lblTest];
}
LOG
RacingGenk[567:c07] log komt hooray this works
希望这澄清了更多我的问题
谢谢
是testLabel在IB连接? – Daniel
@丹尼尔是的。 –
你的问题是什么?即你会期待什么? – ilmiacs