cocoa - 动态结果和覆盖数据

标签 cocoa drawing nstextfield

今天我有一个由此产生的问题:Database Results in Cocoa 。它涉及使用数据库返回的数据来创建一定数量的问题。我正在使用以下代码的形式(这是在问题中发布的)。

NSMutableDictionary * interfaceElements = [[NSMutableDictionary alloc] init];

for (NSInteger i = 0; i < numberOfTextFields; ++i) {
  //this is just to make a frame that's indented 10px
  //and has 10px between it and the previous NSTextField (or window edge)
  NSRect frame = NSMakeRect(10, (i*22 + (i+1)*10), 100, 22);
  NSTextField * newField = [[NSTextField alloc] initWithFrame:frame];
  //configure newField appropriately
  [[myWindow contentView] addSubview:newField];
  [interfaceElements setObject:newField forKey:@"someUniqueIdentifier"];
  [newField release];
}

但是,现在当我尝试使用 IFVerticallyExpandingTextfield (来自 http://www.cocoadev.com/index.pl?IFVerticallyExpandingTextField )或创建任何大量文本时,它只会覆盖其他绘制的内容。我研究过在对象上使用 setAutosizingMask: ,但到目前为止还没有起作用。

感谢您的帮助。

编辑:我想要的效果称为“正确的文本字段”,发生的情况称为“StackOverflow示例”-http://www.mediafire.com/?sharekey=bd476ea483deded875a4fc82078ae6c8e04e75f6e8ebb871 .

编辑2:如果没有人知道如何使用这个 IFVerticallyExpandingTextfield 类,是否有人知道是否有另一种方法可以实现该效果?

最佳答案

你是这个意思吗?

http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaDrawingGuide/GraphicsContexts/GraphicsContexts.html

你的问题对我来说不是很清楚,但这可能会有所帮助^^^。

查看该页面上的“修改当前图形状态”。

从“正确的文本字段”示例中精确复制代码并在您的应用程序中使用它怎么样?或者从“正确的文本字段”示例启动您的应用程序。

还有

http://www.cocoadev.com/index.pl?IFVerticallyExpandingTextField的评论说:

Give it a try! You should be able to throw this into a project, read the files in Interface Builder, and use the custom class pane to make an NSTextField into an IFVerticallyExpandingTextField. You'll need to set the layout and linebreaking attributes for word wrapping for this to work.

Although expansion should work properly when the textfield is embedded in a subview, I'm having some trouble dealing with NSScrollViews. The field expands into the scrollview's content view, but none of the controls on the scrollbar appear. Some help here would be appreciated.

关于cocoa - 动态结果和覆盖数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1257865/

相关文章:

.net - 如何使用 WPF 构建一个简单的形状图表应用程序?

algorithm - 一种类似于谷歌地图中的绘图编码算法

objective-c - ControlTextDidChange 不适用于设置 NSTextField 的字符串

objective-c - 根据字符串的长度更新 NSTextField 的宽度

objective-c - 保留 kPasteboardTypeFileURLPromise 时的错误处理

ios - 由于 UIDatePicker 导致的内存问题

cocoa - 当 View 选择更改时,自定义 NSViewController 表示的对象不会更新

objective-c - 如何检查 NSString 的最后一个字符

javascript - JS/HTML或FLASH Action 图显示

cocoa - NSTextField 子类不尊重 -acceptsFirstResponder?