gpt4 book ai didi

objective-c - TextView 文本追加

转载 作者:行者123 更新时间:2023-12-03 17:52:55 24 4
gpt4 key购买 nike

这就是我的问题:我想构建一个计算器,例如 this ,所以我在窗口中放置了一个 TextView 和一些按钮,但是,现在这就是代码:

文档.h

//
// Document.m
// TheCalcolator
//
// Created by Imac on 15/12/13.
// Copyright (c) 2013 Imac. All rights reserved.
//

#import "Document.h"
#import "FunctionalManager.h"

@implementation Document

- (id)init
{
self = [super init];
if (self) {
// Add your subclass-specific initialization here.
}
return self;
}

- (NSString *)windowNibName
{
// Override returning the nib file name of the document
// If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
return @"Document";
}

- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
[super windowControllerDidLoadNib:aController];
// Add any code here that needs to be executed once the windowController has loaded the document's window.
}

+ (BOOL)autosavesInPlace
{
return YES;
}

- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
// Insert code here to write your document to data of the specified type. If outError != NULL, ensure that you create and set an appropriate error when returning nil.
// You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.
NSException *exception = [NSException exceptionWithName:@"UnimplementedMethod" reason:[NSString stringWithFormat:@"%@ is unimplemented", NSStringFromSelector(_cmd)] userInfo:nil];
@throw exception;
return nil;
}

- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
// Insert code here to read your document from the given data of the specified type. If outError != NULL, ensure that you create and set an appropriate error when returning NO.
// You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead.
// If you override either of these, you should also override -isEntireFileLoaded to return NO if the contents are lazily loaded.
NSException *exception = [NSException exceptionWithName:@"UnimplementedMethod" reason:[NSString stringWithFormat:@"%@ is unimplemented", NSStringFromSelector(_cmd)] userInfo:nil];
@throw exception;
return YES;
}

-(IBAction)aggiungiuno:(id)sender
{
FunctionalManager *func = [[FunctionalManager init] alloc];

[func aggiungitesto:@"1" allaView:textView];
}

@end

这就是FunctionalManager.m:

//
// FunctionalManager.m
// TheCalcolator
//
// Created by Imac on 15/12/13.
// Copyright (c) 2013 Imac. All rights reserved.
//

#import "FunctionalManager.h"

@implementation FunctionalManager

-(void)aggiungitesto:(NSString *)daString allaView:(NSTextView *)view
{
NSString *testoAttuale = view.string;

view.string = [NSString stringWithFormat:@"%@%@", testoAttuale, daString];

}

@end

你能帮我理解错误在哪里吗?因为当我构建它时,这就是 xcode 向我显示的内容:http://it.tinypic.com/r/2z9d6qd/5

最佳答案

你需要这个:

FunctionalManager *func = [[FunctionalManager alloc] init];

你已经向后分配了alloc/init

关于objective-c - TextView 文本追加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20597189/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com