2014-09-10 4 views
0

두 개의 viewCOntroller가 있습니다. 첫 번째에는 단추가 있으며, 눌렀을 때 다른 viewcontroller에 tableview가 포함되어 있습니다. 선택한 tableView 셀은 첫 번째 viewController의 단추에 대한 새 제목이어야합니다.UIButton IBOutlet을 프로그래밍 방식으로 변경

제의 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가 닫히면 버튼 제목이 변경되지 않습니다. 뭐가 문제 야?

+0

위임자를 설정해야합니다. –

답변

0

처음에는 제목이 실제 질문과 일치하지 않습니다. 두 번째로, 첫 번째보기 컨트롤러의 새 객체를 초기화 할 필요가 없습니다. 아직 메모리에 남아 있기 때문에 두 번째 컨트롤러에서 먼저 액세스하거나 시도해야합니다. 위임을 사용하여 두 번째보기 컨트롤러에서 새 제목을받습니다.

관련 문제