Dynamic Results and Covering Data

五迷三道 提交于 2019-12-11 04:41:19

问题


Today I have a question that sprouted off of this one: Database Results in Cocoa. It's regarding using the data that was returned by a database to create a certain number of questions. I am using a form of the following code (this was posted in the question).

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];
}

However, now when I attempt to use IFVerticallyExpandingTextfield (from http://www.cocoadev.com/index.pl?IFVerticallyExpandingTextField), or create any large amount of text, it simply goes over the other drawn content. I looked into using setAutosizingMask: on the object, but it has not worked so far.

Thanks for any help.

EDIT: What I want the effect to look like is called "Correct TextField" and what happens is called "StackOverflow Sample" - http://www.mediafire.com/?sharekey=bd476ea483deded875a4fc82078ae6c8e04e75f6e8ebb871.

EDIT 2: And if no one knows how to use this IFVerticallyExpandingTextfield class, would anyone know if there is another way to accomplish the effect?


回答1:


Do you mean this?

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

Your question is not very clear to me but this might help ^^^.

Look at 'Modifying the Current Graphics State' on that page.

What about just exactly copying the code from the 'Correct textfield' example and use it in your application? Or start your application from the 'Correct texfield' example.

Also

A comment on http://www.cocoadev.com/index.pl?IFVerticallyExpandingTextField says:

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.



来源:https://stackoverflow.com/questions/1257865/dynamic-results-and-covering-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!