我有以下情况。我有一个视图控制器(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];
}
我的第一个和第三个控制器只是在contentController的contentView中显示表视图。但在我的secondController中,我使用了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
希望这能澄清更多我的问题
谢谢
答案 0 :(得分:1)
要让标签更新,您需要将代码更改为这样。
self.testLabel.text = lblTest;