2013-07-02 3 views
2

비슷한 질문을했지만 내 경우에는 아무 것도 작동하지 않았습니다. 내가하고 싶은 일은 아주 쉽지만 왜 그런 일이 일어나는지 알 수는 없다.프로그래밍 방식으로 새 뷰 컨트롤러를 열면 검은 색 화면이 나타납니다.

셀에서 단추를 눌러 프로그래밍 방식으로 새보기 컨트롤러를 열 때를 ​​원합니다. 여기 내 코드입니다 :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    dealViewController=[[DealViewController alloc]init]; 
    if (indexPath.row==0){ 
     [self presentModalViewController:(UIViewController *)dealViewController animated:TRUE]; 
    } 

} 

내 다른 컨트롤러

:

@implementation DealViewController 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
    NSLog(@"Opened"); 
} 

Opened 인쇄되지만 시뮬레이터가 검은 색 화면을 보여줍니다. 나는 또한 이것을 시도했다 :

dealViewController=[[DealViewController alloc]initWithNibName:@"DealViewController" bundle: nil]; 

그러나 나는 segfault를 얻는다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 당신은 스토리 보드를 사용하는 경우

+0

당신은 배경 색상을 변경하고 뭔가가 변경되는지 확인하려고 했습니까? –

+0

스토리 보드를 사용하고 있습니까? – CRDave

+0

그것은 당신의 VC를로드하는 것 같습니다. 뭐가 문제 야? – Pfitz

답변

4

이 시도 다음 코드를 사용하십시오 :

Apple Doc for StoryBoard

또한, 당신이 performSegue 통해 작업을 수행 할 수 있습니다 withIdentifier를.

A Good Tutorial on same

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"<Your StoryBoard_Name" bundle:nil]; 

    dealViewController=[storyboard instantiateViewControllerWithIdentifier:@"ViewController_Identifiter"]; 
     if (indexPath.row==0){ 
      [self presentModalViewController:(UIViewController *)dealViewController animated:TRUE]; 
     } 

    } 
0

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"dealViewController" bundle:nil]; 

    dealViewController=[[DealViewController alloc]initWithNibName:@"DealViewController" bundle: nil]; 
     if (indexPath.row==0){ 
      [self presentModalViewController:(UIViewController *)dealViewController animated:TRUE]; 
     } 

    } 
관련 문제