执行Segue后,NSScrollView丢失了文档视图

时间:2015-04-28 19:12:12

标签: objective-c macos nsscrollview

我正在使用Storyboard开发Mac OS X应用程序。我的主控制器上有一个NSScrollview。这就是它的内容是如何创建的:

-(void)addProduktWithName: (NSString *)NameStr Price: (CGFloat)PriceFl TimesOfProduct: (CGFloat)TOfPFl{

    [MainView setFrameSize: NSSizeFromCGSize(CGSizeMake(ProductScrollView.contentSize.width, (CellsCount + 1) * 25))];

    NSFont *StandardFont = [NSFont fontWithName: @"Helvetica" size: 18];

    //Strings
    NSString *NumberStr = [NSString stringWithFormat: @"%i", CellsCount + 1];
    NSString *PriceStr = [NSString stringWithFormat: @"%.2f", PriceFl];
    NSString *TOfPStr = [NSString stringWithFormat: @"%.2f", TOfPFl];

    NSImageView *PositionCell = [[NSImageView alloc] initWithFrame: CGRectMake(0, CellsCount * 25, 45, 25)];
    [PositionCell setImageScaling: NSImageScaleAxesIndependently];
    [PositionCell setImage: [NSImage imageNamed: @"TableCell3"]];
    [MainView addSubview: PositionCell];

    NSImageView *CellStyle = [[NSImageView alloc] initWithFrame: CGRectMake(45, CellsCount * 25, ProductScrollView.contentSize.width - 45, 25)];
    [CellStyle setImageScaling: NSImageScaleAxesIndependently];

    if ((CellsCount % 2) == 0) {
        [CellStyle setImage: [NSImage imageNamed: @"TableCell"]];
    } else {
        [CellStyle setImage: [NSImage imageNamed: @"TableCell2"]];
    }
    [MyView addSubview: CellStyle];

    NSTextField *Index = [[NSTextField alloc] initWithFrame: CGRectMake(0, CellsCount * 25, 45, 25)];
    [Index setStringValue: NumberStr];
    [Index setFont: StandardFont];
    [Index setBezeled:NO];
    [Index setDrawsBackground:NO];
    [Index setEditable:NO];
    [Index setSelectable:NO];
    [Index setAlignment: NSCenterTextAlignment];
    [MainView addSubview: Index];

    NSTextField *Number = [[NSTextField alloc] initWithFrame: CGRectMake(60, CellsCount * 25, 45, 25)];
    [Number setStringValue: TOfPStr];
    [Number setFont: StandardFont];
    [Number setBezeled:NO];
    [Number setDrawsBackground:NO];
    [Number setEditable:NO];
    [Number setSelectable:NO];
    [Number setAlignment: NSCenterTextAlignment];
    [MainView addSubview: Number];

    NSTextField *Product = [[NSTextField alloc] initWithFrame: CGRectMake(105, CellsCount * 25, ProductScrollView.contentSize.width - 205, 25)];
    [Product setStringValue: NameStr];
    [Product setFont: StandardFont];
    [Product setBezeled:NO];
    [Product setDrawsBackground:NO];
    [Product setEditable:NO];
    [Product setSelectable:NO];
    [Product setAlignment: NSLeftTextAlignment];
    [MainView addSubview: Product];

    NSTextField *Price = [[NSTextField alloc] initWithFrame: CGRectMake(ProductScrollView.contentSize.width - 100, CellsCount * 25, 100, 25)];
    [Price setStringValue: [PriceStr stringByAppendingString: @" €"]];
    [Price setFont: StandardFont];
    [Price setBezeled:NO];
    [Price setDrawsBackground:NO];
    [Price setEditable:NO];
    [Price setSelectable:NO];
    [Price setAlignment: NSRightTextAlignment];
    [MainView addSubview: Price];

    [ProductScrollView setDocumentView: MainView];

    CellsCount += 1;

}

现在我正在对#34; Pay" -ViewController执行Segue,并且我允许MainView访问该控制器,以便可以在那里显示View。

-(void)prepareForSegue:(NSStoryboardSegue *)segue sender:(id)sender{
    if ([segue.identifier isEqualToString: @"ShowPay"]) {
        [segue.destinationController setProductView: MainView];
    }
}

在我的付款观点中:

-(void)setProductView:(NSView *)myView{
    ProductView = myView;
}

现在,如果用户想取消付款并进行编辑,他可以点击按钮,我的主控制器将再次显示。但是,如果我调用addProduct-Method,则仅显示Scrollview的内容。 (你知道,那不是我想要的,因为,然后他添加了一个产品,我必须在一个按钮上再次显示我的ScrollView!) MainView不会松动。一切仍然存在但滚动视图不再显示了!也许有一个方法,在解除一个控制器之后被调用,我可以在那里再次设置文档视图......

感谢您的帮助!

0 个答案:

没有答案