- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的意图是为带有两个 Pane 的 NSSplitView 提供 2 个单独的 View Controller 。在左 Pane 中,我想要一个表格 View ,但它崩溃了。这是场景:
我有一个带有 MainMenu.xib、AppDelegate.h/m 的简单项目。在这个项目中,我添加了一个 LeftPaneViewController.h/.m/.xib。
在 MainMenu.xib 中,我将 NSSplitView 添加到默认 View 。
在 AppDelegate.h 中:
@property (weak) IBOutlet NSSplitView *splitView;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
LeftPaneViewController *lpvc = [[LeftPaneViewController alloc] initWithNibName:@"LeftPaneViewController" bundle:nil];
[self.splitView replaceSubview:[[self.splitView subviews] objectAtIndex:0] with:lpvc.view];
}
@interface LeftPaneViewController : NSViewController <NSTableViewDelegate, NSTableViewDataSource>
@property (weak) IBOutlet NSTableView *tableView;
@property (nonatomic, retain) NSMutableArray *tableDataSource;
#import "LeftPaneViewController.h"
@interface LeftPaneViewController ()
@end
@implementation LeftPaneViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Initialization code here.
}
return self;
}
- (void)awakeFromNib
{
self.tableDataSource = [[NSMutableArray alloc] initWithObjects:@"Row1", @"Row2", nil];
[self.tableView setNeedsDisplay];
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
// This is a defensive move
// There are cases where the nib containing the NSTableView can be loaded before the data is populated
// by ensuring the count value is 0 and checking to see if the namesArray is not nil, the app
// is protecting itself agains that situation
NSInteger count=0;
if (self.tableDataSource)
count=[self.tableDataSource count];
return count;
}
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
// Get an existing cell with the MyView identifier if it exists
NSTextField *result = [tableView makeViewWithIdentifier:@"LeftPaneCell" owner:self];
// There is no existing cell to reuse so create a new one
if (result == nil) {
// Create the new NSTextField with a frame of the {0,0} with the width of the table.
// Note that the height of the frame is not really relevant, because the row height will modify the height.
NSTextField *textField;
textField = [[NSTextField alloc] initWithFrame:NSMakeRect(2, 456, 125, 20)];
[textField setStringValue:@"My Label"];
[textField setBezeled:NO];
[textField setDrawsBackground:NO];
[textField setEditable:NO];
[textField setSelectable:NO];
[self.view addSubview:textField];
// The identifier of the NSTextField instance is set to MyView.
// This allows the cell to be reused.
result.identifier = @"LeftPaneCell";
}
// result is now guaranteed to be valid, either as a reused cell
// or as a new cell, so set the stringValue of the cell to the
// nameArray value at row
result.stringValue = [self.tableDataSource objectAtIndex:row];
// Return the result
return result;
}
@end
* thread #1: tid = 0x23427, 0x00007fff82893250 libobjc.A.dylib`objc_msgSend + 16, queue = 'com.apple.main-thread, stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
frame #0: 0x00007fff82893250 libobjc.A.dylib`objc_msgSend + 16
frame #1: 0x00007fff88f8d972 AppKit`-[NSTableRowData _addViewToRowView:atColumn:row:] + 324
frame #2: 0x00007fff88f8d63f AppKit`-[NSTableRowData _addViewsToRowView:atRow:] + 151
frame #3: 0x00007fff88f8bbd5 AppKit`-[NSTableRowData _addRowViewForVisibleRow:withPriorView:] + 415
frame #4: 0x00007fff88f8b95a AppKit`-[NSTableRowData _addRowViewForVisibleRow:withPriorRowIndex:inDictionary:withRowAnimation:] + 272
frame #5: 0x00007fff88f8ac29 AppKit`-[NSTableRowData _unsafeUpdateVisibleRowEntries] + 740
frame #6: 0x00007fff88f8a7c1 AppKit`-[NSTableRowData updateVisibleRowViews] + 119
frame #7: 0x00007fff88f625a7 AppKit`-[NSTableView layout] + 165
frame #8: 0x00007fff88f15e65 AppKit`-[NSView _layoutSubtreeHeedingRecursionGuard:] + 112
frame #9: 0x00007fff8d11b4a6 CoreFoundation`__NSArrayEnumerate + 582
frame #10: 0x00007fff88f15fc6 AppKit`-[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
frame #11: 0x00007fff8d11b4a6 CoreFoundation`__NSArrayEnumerate + 582
frame #12: 0x00007fff88f15fc6 AppKit`-[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
frame #13: 0x00007fff8d11b4a6 CoreFoundation`__NSArrayEnumerate + 582
frame #14: 0x00007fff88f15fc6 AppKit`-[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
frame #15: 0x00007fff8d11b4a6 CoreFoundation`__NSArrayEnumerate + 582
frame #16: 0x00007fff88f15fc6 AppKit`-[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
frame #17: 0x00007fff8d11b4a6 CoreFoundation`__NSArrayEnumerate + 582
frame #18: 0x00007fff88f15fc6 AppKit`-[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
frame #19: 0x00007fff8d11b4a6 CoreFoundation`__NSArrayEnumerate + 582
frame #20: 0x00007fff88f15fc6 AppKit`-[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
frame #21: 0x00007fff88f15cfe AppKit`-[NSView layoutSubtreeIfNeeded] + 615
frame #22: 0x00007fff88f114ac AppKit`-[NSWindow(NSConstraintBasedLayout) layoutIfNeeded] + 201
frame #23: 0x00007fff88e0b0a8 AppKit`_handleWindowNeedsDisplayOrLayoutOrUpdateConstraints + 446
frame #24: 0x00007fff893d6901 AppKit`__83-[NSWindow _postWindowNeedsDisplayOrLayoutOrUpdateConstraintsUnlessPostingDisabled]_block_invoke_01208 + 46
frame #25: 0x00007fff8d0e9417 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
frame #26: 0x00007fff8d0e9381 CoreFoundation`__CFRunLoopDoObservers + 369
frame #27: 0x00007fff8d0c47b8 CoreFoundation`__CFRunLoopRun + 728
frame #28: 0x00007fff8d0c40e2 CoreFoundation`CFRunLoopRunSpecific + 290
frame #29: 0x00007fff8c17aeb4 HIToolbox`RunCurrentEventLoopInMode + 209
frame #30: 0x00007fff8c17ab94 HIToolbox`ReceiveNextEventCommon + 166
frame #31: 0x00007fff8c17aae3 HIToolbox`BlockUntilNextEventMatchingListInMode + 62
frame #32: 0x00007fff88e08533 AppKit`_DPSNextEvent + 685
frame #33: 0x00007fff88e07df2 AppKit`-[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
frame #34: 0x00007fff88dff1a3 AppKit`-[NSApplication run] + 517
frame #35: 0x00007fff88da3bd6 AppKit`NSApplicationMain + 869
frame #36: 0x0000000100001872 TableView_In_SplitView`main(argc=3, argv=0x00007fff5fbff7e8) + 34 at main.m:13
frame #37: 0x00007fff84d4d7e1 libdyld.dylib`start + 1
最佳答案
好的,找到答案了。由于 AppDelegate.m 中的 LeftPaneViewController 变量 (lpvc) 是本地的,因此它在 replaceSubview 调用之后被释放。因此,在 AppDelegate.h 中将其添加为 (nonatomic, retain) 修复了崩溃。打开僵尸来寻找答案;-)。
关于crash - NSTableView 在添加到 SplitView 的自定义 View 中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20660863/
非常基本的场景: 我的 Nib 上有一个 NSTableView,有一个指向它的 socket 。我的应用程序委托(delegate)中有以下内容: - (void)applicationDidFin
目前,当我从 NSTableView 中拖出一行时,它是该行中的半透明文本。相反,我想显示代表这一行的半透明图像。 我怎样才能做到这一点? 最佳答案 我建议覆盖 -[NSTableView dragI
我正在使用 NSTableView 来显示我的数据。我想删除默认情况下采用蓝色的选定行的颜色。我可以将其设置为透明颜色吗?可能吗? 编辑: 如何去掉这个蓝色边框?我已将Clear color 设置为表
我正在尝试在 NSTableView 内显示 NSTableView。这是一个类似 iTunes 的专辑/轨道 View 。所以有一个包含 10 张专辑的列表,每个专辑都有一些轨道。我想在外部表格 V
我有一个基于 View 的 NSTableView,其内容绑定(bind)到数组 Controller 。我使用 objectValue.title 绑定(bind)一个特定的文本字段。这工作正常。我
具有单列的基于 View 的 NSTableView。每个“单元格”包含多个 NSTextField、一个 NSImageView 和一个 NSButton,所有这些都绑定(bind)到表格单元格 V
如果我的理解没有错的话,cell-based NSTableView 和 view-based NSTableView 是同一类型的实例。那么,cpu是如何区分cell-based和view-base
我在 10.8 上运行基于 View 的 NSTableView 时遇到问题(目标是 10.7,但我认为这不相关)。 我正在使用 NSTableView,并通过绑定(bind)获取自定义 NSTabl
我有一个有 4 列的 NSTableView。我还为每一行设置了自定义背景颜色。唯一的问题是我有这些丑陋的空白区域,网格线会同时出现在水平轴和垂直轴上。我在 IB 中都取消了检查,但它们仍然出现。如何
我有一个基于 View 的 NSTableView,每一行都必须生成一些需要时间的图像。这些是在后台 NSoperationQueue 上完成的,并在请求图像时启动(通过绑定(bind))。 当一行滚
我的NSTableCellView是子类,并存储指向对象的指针。我想访问该指针,而我唯一获得的信息就是row编号为NSInteger。 如何使用给定的NSTableCellView从我的tableVi
我需要创建一个包含 3 列的 NSTableView,这些列必须适合像这样的空间 20% 60% 20%。我在界面生成器中设置了约束但没有成功。结果总是一样的。显示了 3 列,但大小与 IB 中的相同
我已经尝试了其他帖子中建议选项的多种组合,但我似乎无法使用基于单元格的 NSTableView 填充不可编辑的 NSTextFieldCell 来选择单元格而不是行。 我已经尝试过: [[co
我在区分两个 NSTableView 时遇到问题,需要一些帮助。 我尝试过这些方法: 1. - (void)tableViewSelectionDidChange:(NSNotification *)
我将 NSTableView 绑定(bind)到 NSArrayController。由于某种原因,我根本无法对列进行排序。有些列甚至不显示排序方向箭头。有些确实显示了它,但单击它只是切换箭头方向,它
我在 TableView 中第一行的索引是“0”,这是正确的吗? 如果是,我怎样才能使 TableView 中第一行的索引变为“1”? 这是需要的,因为我的 DataSourse 从“1”开始,我需要
我编写了一个向 NSTableView 添加新行的方法。它添加了新行,但有空,没有文本。代码如下: AppDelegate.h #import @interface AppDelegate : NS
建立委托(delegate)和数据源连接后,我有以下 Controller : #import @interface KextTable : NSObject { @private NSA
我在基于 View 的 NSTableView 中对 NSTableRowView 进行了子类化,以将选择颜色更改为浅蓝色,而不是默认颜色。 不幸的是,当我选择该行时,自定义单元格内的标签和文本字段的
我有一个包含 3 个单元格的 NSTableView。我已经使用以下代码调整了该表格 View 以显示分隔符: [self.tableView setGridColor:[NSColor ligh
我是一名优秀的程序员,十分优秀!