1

我在我的视图控制器中创建了一个 UIPopover 控制器,它会打开一个包含项目列表的弹出窗口。我想要它,以便如果我在列表中选择一个项目,主视图上的标签会更新以显示此选择。到目前为止,我已经尝试使用下面的代码,但是当我单击列表中的某个项目时,出现以下错误:-[ASHAppDelegate portfolioLabel]: unrecognized selector sent to instance 0x6e4fe80

我用于 UIPopOverController 的代码如下所示:

-(IBAction) portFoliosButtonPress:(id)sender {

if (self.portfolioPopoverController == nil) {
    ASHPortfolioViewController *portfoliosTableViewController = [[ASHPortfolioViewController alloc] initWithStyle:UITableViewStylePlain];
    //CGSize frame = {portfoliosTableViewController.view.frame.size.width, 200.0};
    UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:portfoliosTableViewController]; 
     CGSize frame = {300.0, 230.0};
    [popover setPopoverContentSize:frame];
    popover.delegate = self;

    self.portfolioPopoverController = popover;
    //self.contentSizeForViewInPopover.height = CGSizeMake(150.0, 140.0);
}

if ([self.portfolioPopoverController isPopoverVisible]) {
    [self.portfolioPopoverController dismissPopoverAnimated:YES];    
}
else {
    [self.portfolioPopoverController presentPopoverFromBarButtonItem:sender 
                                            permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
self.portfolioLabel.text = @"hi";

}
#pragma mark - Popover lifecycle

//---called when the user clicks outside the popover view---
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController {

NSLog(@"popover about to be dismissed");
return YES;
}

//---called when the popover view is dismissed---
- (void)popoverControllerDidDismissPopover:
(UIPopoverController *)popoverController {

    NSLog(@"popover dismissed");    
}

弹出框控制器包含的 UITableView 中使用的代码如下所示:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath   *)indexPath
{

    ASHFirstViewController *appDelegate =(ASHFirstViewController *)[[UIApplication sharedApplication] delegate];    
    appDelegate.portfolioLabel.text = @"Test"; 
}

'portfolioLabel' 是我的视图控制器中的一个 IBOutlet UIlabel。

4

0 回答 0