0

UIPopoverController 셀을 클릭하면 ViewController을 열어야합니다. SeccionesViewController은 내가 UIPopoverController에 넣은 ViewController입니다. 이것이 테이블입니다. 작동하지 않는 기능은 didSelectRowAtIndexPath에서 TableView입니다.UIPopoverController의 셀을 클릭하면 새 UIViewController 푸시

진심으로 감사드립니다.

UIPopoverController을 보여 내 코드는 다음과 같습니다

-(IBAction)seccionesButtonTapped:(id)sender 
{ 

     if (_itemPicker == nil) { 
      //Create the ColorPickerViewController. 
      _itemPicker = [[SeccionesViewController alloc] initWithStyle:UITableViewStylePlain]; 

      //Set this VC as the delegate. 
      _itemPicker.delegate = self; 
     } 

     if (_itemPickerPopover == nil) { 
      //The color picker popover is not showing. Show it. 
      _itemPickerPopover = [[UIPopoverController alloc] initWithContentViewController:_itemPicker]; 
      //[_itemPickerPopover presentPopoverFromBarButtonItem:(UIBarButtonItem *) sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; 
      [_itemPickerPopover presentPopoverFromRect:CGRectMake(350, 902, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES]; 
     } else { 
      //The color picker popover is showing. Hide it. 
      [_itemPickerPopover dismissPopoverAnimated:YES]; 
     } 
} 

SeccionesViewController 코드는 다음과 같습니다

 //Set this VC as the delegate. 
     _itemPicker.delegate = self; 

당신이있어 것처럼 보이게 :

-(id)initWithStyle:(UITableViewStyle)style 
{ 
    if ([super initWithStyle:style] != nil) { 

     //Initialize the array 
     _itemNames = [NSMutableArray array]; 

     //Set up the array of colors. 
     [_itemNames addObject:AMLocalizedString(@"listaTareas", @"")]; 
     [_itemNames addObject:AMLocalizedString(@"EventosTab", @"")]; 

     //Make row selections persist. 
     self.clearsSelectionOnViewWillAppear = NO; 

     //Calculate how tall the view should be by multiplying the individual row height 
     //by the total number of rows. 
     NSInteger rowsCount = [_itemNames count]; 
     NSInteger singleRowHeight = [self.tableView.delegate tableView:self.tableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; 
     NSInteger totalRowsHeight = rowsCount * singleRowHeight; 

     //Calculate how wide the view should be by finding how wide each string is expected to be 
     CGFloat largestLabelWidth = 0; 
     for (NSString *itemName in _itemNames) { 
      //Checks size of text using the default font for UITableViewCell's textLabel. 
      CGSize labelSize = [itemName sizeWithFont:[UIFont boldSystemFontOfSize:20.0f]]; 
      if (labelSize.width > largestLabelWidth) { 
       largestLabelWidth = labelSize.width; 
      } 
     } 

     //Add a little padding to the width 
     CGFloat popoverWidth = largestLabelWidth + 100; 

     //Set the property to tell the popover container how big this view will be. 
     self.contentSizeForViewInPopover = CGSizeMake(popoverWidth, totalRowsHeight); 
    } 

    return self; 
} 

#pragma mark - View Lifecycle 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

#pragma mark - Table view data source 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return [_itemNames count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    // Configure the cell... 
    cell.textLabel.text = [_itemNames objectAtIndex:indexPath.row]; 

    return cell; 
} 

#pragma mark - Table view delegate 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *selectedItem = [_itemNames objectAtIndex:indexPath.row]; 

    NSUserDefaults *dispositivo = [NSUserDefaults standardUserDefaults]; 
    NSString *dis = [dispositivo stringForKey:@"dispositivo"]; 

    if ([selectedItem isEqualToString:AMLocalizedString(@"listaTareas", @"")]) { 

     UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:dis bundle:nil]; 
     ListaTareasViewController *tareas= [storyBoard instantiateViewControllerWithIdentifier:@"ListaTareasView"]; 
     tareas.communitykey = communitykey; 
     tareas.tituloAsig = tituloAsig; 
     tareas.infoH = infoH; 
     if ((vengoDe != 1) && (vengoDe != 2) && (vengoDe != 3)) { 
      tareas.vengoDe = 1; 
     }else{ 
      tareas.vengoDe = vengoDe; 
     } 
     tareas.infoAsig = infoAsig; 
     [self.navigationController pushViewController:tareas animated:YES]; 

    }else if ([selectedItem isEqualToString:AMLocalizedString(@"EventosTab", @"")]){ 

     UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:dis bundle:nil]; 
     ListaEventosViewController *eventos= [storyBoard instantiateViewControllerWithIdentifier:@"listaEventosView"]; 
     eventos.communitykey = communitykey; 
     eventos.nomAsig = tituloAsig; 
     eventos.infoH = infoH; 
     if ((vengoDe != 1) && (vengoDe != 2) && (vengoDe != 3)) { 
      eventos.vengoDe = 1; 
     }else{ 
      eventos.vengoDe = vengoDe; 
     } 
     eventos.infoAsig = infoAsig; 
     [self.navigationController pushViewController:eventos animated:YES]; 

    } 


} 

답변

1

당신이 코드를 가지고 바른 길에. 그런 다음 스토리 보드를 다시로드하고 컨트롤러를 인스턴스화 한 다음 컨트롤러가 존재하지 않는 탐색 컨트롤러에 밀어 넣습니다 (충돌이 발생하지 않지만 결과가 표시되지 않음).

해야 할 일은 위임 관계를 사용하여 selectedItem을 소스보기 컨트롤러로 다시 전달하는 것입니다. 일단 그보기 컨트롤러는 내비게이션 컨트롤러에 액세스 할 수 있으므로 selectedItem을 사용하여 컨트롤러를 만들고 해당 컨트롤러를 표시하도록 밀어 넣는 방법을 결정할 수 있습니다.

selectedItem 대신 tareas/eventos을 대리인에게 다시 전달할 수 있습니다. 어떤 뷰 컨트롤러가 필요한지, 어떻게 구성해야하는지에 대한 지식을 소유해야하는 사람은 앱 구조에 따라 결정해야합니다.

+0

다음과 같이하십시오 :'self.navigationController.delegate = self;'?? – amurcia

+0

미안하지만, 매우 분실했습니다 ... – amurcia

+0

아니요, 델리게이트로 돌아가는 것은'[self.delegate seccionesViewController : self didSelectItem : ## XXX ##];'## XXX ##는보기와 같습니다. 컨트롤러 또는 선택한 항목. – Wain

관련 문제