以编程方式更改UIButton IBOutlet

时间:2014-09-10 06:50:09

标签: ios objective-c uitableview uibutton

我有两个viewControllers,第一个有一个按钮,按下时会显示另一个包含tableview的viewcontroller。所选的tableView单元格应该是第一个viewController上按钮的新标题。

第一个viewController .h

@property (weak, nonatomic) IBOutlet UIButton *btn1Out;
- (IBAction)btn1:(id)sender;

第一个viewController .m

- (IBAction)btn1:(id)sender
{
viewcontroller2 = [[PopUpViewController alloc] init];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewcontroller2];

[self.navigationController presentViewController:navController animated:YES completion:nil];
}

viewController 2 .h

@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSString *currentStartStation;

viewController 2 .m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.selectedCell = [NSString stringWithFormat:@"Cell %d", indexPath.row+1];

[self.navigationController dismissViewControllerAnimated:YES completion:nil];


NewViewController *firstViewControllerObj = [[NewViewController alloc] init];

[firstViewControllerObj.btn1Out setTitle:[NSString stringWithFormat:@"%@", self.selectedCell] forState:UIControlStateNormal];

}

当viewController2被解除时,按钮标题不会被更改。怎么了?

1 个答案:

答案 0 :(得分:0)

首先你的标题与真正的问题不匹配...第二,不需要初始化你的第一个视图控制器的新对象,因为它仍然在内存中,你需要从第二个控制器访问到第一个或尝试使用委托从第二个视图控制器接收新标题。

相关问题