在我的cocoa应用程序中,我需要一个用于NSTableView的自定义NSCell.此NSCell子类包含用于处理单击的自定义NSButtonCell(以及用于文本内容的两个或三个NSTextFieldCells).您将在下面找到我的代码的简化示例.
@implementation TheCustomCell
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
// various NSTextFieldCells
NSTextFieldCell *titleCell = [[NSTextFieldCell alloc] init];
....
// my custom NSButtonCell
MyButtonCell *warningCell = [[MyButtonCell alloc] init];
[warningCell setTarget:self];
[warningCell setAction:@selector(testButton:)];
[warningCell drawWithFrame:buttonRect inView:controlView];
}
Run Code Online (Sandbox Code Playgroud)
我坚持的问题是:在这个NSCell中使用该按钮(更确切地说:NSButtonCell)以正常工作的最佳/正确方法是什么?"工作"表示:触发指定的操作消息并在单击时显示备用图像.开箱即用,按钮在单击时不执行任何操作.
很难找到关于这个主题的信息/读物.我在网上找到的唯一帖子指出我要实施
- (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView *)controlView untilMouseUp:(BOOL)untilMouseUp;
Run Code Online (Sandbox Code Playgroud)
这是正确的方法吗?实现trackMouse:在我的包含NSCell中?然后将事件转发给NSButtonCell?我本来期望NSButtonCell本身知道在点击它时该做什么(我看到trackMouse:方法更多的是在cunjunction,真正跟踪鼠标移动 - 而不是作为'标准'点击行为的训练轮).但是当它被包含在一个单元格本身时似乎不会这样做......似乎我还没有掌握自定义单元格的大图,但是;-)
如果有人能够根据自己的经验回答这个问题(或指向我的某些教程等),我会很高兴 - 告诉我我是否走在正确的轨道上.
托比,提前谢谢
在iOS5中,在故事板上使用ARC和原型单元格用于tableView,我可以替换下面的代码:
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
// Configure the cell...
return cell;
Run Code Online (Sandbox Code Playgroud)
有了这个简单的代码??:
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"Cell"];
return cell;
Run Code Online (Sandbox Code Playgroud)
我在这个链接上看到了这个:
http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1
提前致谢!
Arildo
我正在开发一个Iphone应用程序,我可以使用Assetslibrary枚举资产并将它们加载到表格视图中.用户可以删除应用程序中的行(图片/视频),但如何直接从我的应用程序更新Iphone相册?否则,在刷新时,tableview将重新加载以前删除的资产.
如何隐藏ListView的水平滚动条?我尝试了不同的方式,可能它很简单,但我无法让它运行.
我的问题是如何在第一列中使用tableRow的索引在JavaFX中创建一个新表.
所以我创建了一个类:NrCellFactory.
public class NrCellFactory<S, String> extends TableCellFactory<S,String> {
private class NrCell<S,String> extends TableCell<S,String>{
public NrCell(){
setText(this.getTableRow().getIndex()+"");
}
}
@Override
protected TableCell<S, String> createTableCell(TableColumn<S, String> column) {
return new NrCell();
}
}
Run Code Online (Sandbox Code Playgroud)
然后我设置我的列应显示数字:
nrCol.setCellFactory(new NrCellFactory<Person,String>());
Run Code Online (Sandbox Code Playgroud)
当我加载项目时,nrCol没有数据......
有人能解决这个问题吗?
谢谢
JavaFX TableView有一个占位符属性,它基本上是在它为空时Node显示的TableView.如果此属性设置为null(其默认值),则它显示为一个Label或其他一些基于Node"表中没有内容"的文本.
但是如果表中有任何数据行,则占位符将Node消失,并且整个垂直空间TableView将填充行,如果没有足够的数据填充整个表,则包括空行.
这些空行是我想要的,即使表是空的.换句话说,我根本不想使用占位符.有谁知道我怎么做到这一点?
我宁愿不做什么事情,就像TableView在它应该实际上是空的时候放一个空洞的行.
如何在不重新加载所有表的情况下执行此操作?
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *header;
if(!self.searchBar)
{
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 10, 270, kRowHeight)];
self.searchBar.delegate = self;
self.searchBar.barStyle = UISearchBarStyleDefault;
self.searchBar.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
self.searchBar.barTintColor = [UIColor clearColor];
}
if(!self.placeholderSearchBarView)
{
self.placeholderSearchBarView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 270, kSearchBarPlaceholderHeight)];
self.placeholderSearchBarView.backgroundColor = [UIColor colorWithWhite:0.9 alpha:0.7];
}
if (self.showSearchBar)
{
for (UIView *v in self.tableView.tableHeaderView.subviews)
{
if (v.tag == 3433)
{
[v removeFromSuperview];
}
}
header = self.searchBar;
} else {
header = self.placeholderSearchBarView;
}
return header;
}
Run Code Online (Sandbox Code Playgroud) DetailViewController:
@IBOutlet var selectedBundesland: UILabel!
Run Code Online (Sandbox Code Playgroud)
TableViewController:
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
if (segue.identifier == "BackToCalculator") {
var vc:FirstViewController = segue.destinationViewController as FirstViewController
vc.selectedBundesland.text = "Test"
}
Run Code Online (Sandbox Code Playgroud)
IBOutlet已连接!
错误:致命错误:在解包可选值时意外发现nil
我阅读了关于Optionals的多个页面,但我不知道我的问题的答案.
您是否需要有关我的项目的更多信息?
我正在尝试在表格视图的第一个单元格的顶部添加图像.如何让表格视图有一个上边距?现在,图像只是与tableview重叠.我试图让表格视图稍微下降.我不想让它变小或类似的东西.我只想在tableview的顶部添加一个按钮.
//
// usersVC.swift
// CaastRun
//
// Created by Computer on 5/23/15.
// Copyright (c) 2015 Caast. All rights reserved.
//
import UIKit
class usersVC: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var resultsTable: UITableView!
var resultsNameArray = [String]()
var resultsUserNameArray = [String]()
var resultsImageFiles = [PFFile]()
override func viewDidLoad() {
super.viewDidLoad()
let theWidth = view.frame.size.width
let theHeight = view.frame.size.height
resultsTable.frame = CGRectMake(0, 0, theWidth, theHeight)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be …Run Code Online (Sandbox Code Playgroud) 在xcode9.0中,我向storyboard添加了一个tableview,当我将tableview样式切换为分组,xcode崩溃时.