为什么Executor接口没有一个将Callable作为参数的方法?(Why Executor interface doesn't have a method, which takes Callable as a parameter?)
从这个答案我了解到,
Callable
和Runnable
之间唯一的区别是前者可以返回执行结果并抛出异常。我不明白为什么
Executor
没有定义一个需要Callable
的方法:void execute(Callable command);
从我的角度来看,为
Runnable
和Callable
创建方法是合乎逻辑的。 在ExecutorService
的子接口submit()
,Runnable
和Callable
都有类似的submit()
方法。请解释这个设计决定,因为我在互联网上找不到任何解释。
From this answer I learned that the only difference between
Callable
andRunnable
is that former can return a result of the execution and throw an exception.I don't understand why
Executor
doesn't define a method which takes aCallable
:void execute(Callable command);
From my point of view, it'd be logical to create methods for both
Runnable
andCallable
. InExecutorService
, which is a subinterface ofExecutor
, there are similarsubmit()
methods for bothRunnable
andCallable
.Please, explain this design decision, because I can't find any explanation on the Internet.
原文:https://stackoverflow.com/questions/47433992
最满意答案
设置你的单元格标识符选择你的单元格,然后你会在
Attributes Inspector
看到Identifier字段,在那里设置你的重用标识符......就是这样。另请尝试添加: -
func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 }
并更换
let cell = tableView.dequeueReusableCellWithIdentifier("contactDetail") as! ContactDetailTableViewCell
至
let cell = tableView.dequeueReusableCellWithIdentifier("contactDetail", forIndexPath: indexPath) as! ContactDetailTableViewCell
说明
CMD + CLICK上的函数名称:
dequeueReusableCellWithIdentifier
- 您将被引导到它的文档..public func dequeueReusableCellWithIdentifier(identifier: String) -> UITableViewCell? // Used by the delegate to acquire an already allocated cell, in lieu of allocating a new one. @available(iOS 6.0, *) public func dequeueReusableCellWithIdentifier(identifier: String, forIndexPath indexPath: NSIndexPath) -> UITableViewCell // newer dequeue method guarantees a cell is returned and resized properly, assuming identifier is registered
dequeueReusableCellWithIdentifier(identifier: String, forIndexPath indexPath: NSIndexPath)
保证你有一个单元格..也许这些链接是有帮助的: -
To set your cell identifier Select your cell then you will see Identifier field in
Attributes Inspector
, set your reuse identifier there... That's about it..Also try adding :-
func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 }
and replace
let cell = tableView.dequeueReusableCellWithIdentifier("contactDetail") as! ContactDetailTableViewCell
to
let cell = tableView.dequeueReusableCellWithIdentifier("contactDetail", forIndexPath: indexPath) as! ContactDetailTableViewCell
EXPLANATION
CMD+CLICK on the function Name :
dequeueReusableCellWithIdentifier
-- you will be directed to its documentation ..public func dequeueReusableCellWithIdentifier(identifier: String) -> UITableViewCell? // Used by the delegate to acquire an already allocated cell, in lieu of allocating a new one. @available(iOS 6.0, *) public func dequeueReusableCellWithIdentifier(identifier: String, forIndexPath indexPath: NSIndexPath) -> UITableViewCell // newer dequeue method guarantees a cell is returned and resized properly, assuming identifier is registered
dequeueReusableCellWithIdentifier(identifier: String, forIndexPath indexPath: NSIndexPath)
guarantees you a cell..Maybe these links are helpful :-
Fatal error: unexpectedly found nil while unwrapping an Optional values
相关问答
更多-
尝试将viewsDict的类型显式设置为[String: UIView] : let viewsDict: [String: UIView] = ["panelView": panelView, "tableView": tableView] Try explicitly setting the type of viewsDict as [String: UIView]: let viewsDict: [String: UIView] = ["panelView": panelView, "tableVi ...
-
我认为这是因为当你第一次注册时它不再进入你的cell == nil了。 因此,我的建议是将更新文本移到if语句之外。 喜欢这个: if cell == nil { tableView.registerNib(UINib(nibName: "CustomOneCell", bundle: nil), forCellReuseIdentifier: identifier) cell = tableView.dequeueReusableCellWithIdentifier(identifier, ...
-
自从MainStory板出现以来,我不是它的忠实粉丝,我在同一天晚上遇到了同样的错误,我不得不摆脱我的View Controller并用.xib文件制作一个View Controller。 我从我的项目中删除了ViewController 然后我去了AppDelagate并添加了一个变量来创建我自己的ViewController var viewController: ViewController? 在返回之前的didFinishLaunchingWithOptions:函数下 我添加了以下代码 self. ...
-
这不是标题在表格视图中的工作方式。 您可以使用tableHeaderView属性为整个表格创建一个标题(而不是每个章节的标题); 但是如果你想要一个总是显示在屏幕上的小部件,最好创建另一个视图控制器,并将该表添加为子视图。 That's not how the header works in a table view. You can create a header for the whole table (as opposed to a per-section title) using the table ...
-
设置你的单元格标识符选择你的单元格,然后你会在Attributes Inspector看到Identifier字段,在那里设置你的重用标识符......就是这样。 另请尝试添加: - func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } 并更换 let cell = tableView.dequeueReusableCellWithIdentifier("contactDetail") as! C ...
-
如上所述,显示页眉和页脚需要实现UITableViewDelegate协议的相关方法。 对于页脚,它是: tableView(tableView: UITableView, viewForFooterInSection section: Int) 确保正确设置了表视图的委托。 另请注意,还有另一种方便的表视图功能:将在整个表视图下方添加一个页脚,而不管数据源或委托实现如何。 只需指定一个tableFooterView 。 As noted, displaying headers and footers n ...
-
这里是让它工作,让我们从故事板开始: 1拖动ViewController并将TableView和TableViewCell放入其中,不要忘记为您的单元格指定标识符。 2 - 选择TableView然后从连接检查器中将dataSource和委托连接到ViewController 。 现在让我们进入你想要管理TableView ViewController类: 1-在类声明UIViewController,UITableViewDataSource,UITableViewDelegate之后实现两个tablev ...
-
试试这个代码: override func viewDidLoad() { super.viewDidLoad() tableView = UITableView() tableView.dataSource = self tableView.delegate = self self.view.addSubview(self.tableView) //Auto-set the UITableViewCells height (requires iOS8) ...
-
好的,所以你遇到的问题是显示数组的viewController也“拥有”数组。 这意味着(使用您当前的设置)能够更改所需的数组,以获取viewController以便能够访问数组。 您需要通过从该viewController中删除数组来更改此设置。 您仍然可以使用单例(如果您愿意)执行此操作,但创建一个名为ArrayManager全新类。 这将包含数组和所有更新数组的方法。 因此,例如,如果您的viewController有一个名为- (void)addObjectToArray:(id)object;的方 ...
-
如果你在storyboard中添加了tableview,那么在这种情况下你不需要初始化代码中的视图组件你不需要像你提到的那样下面的行 self.tbl_SlideMenu = [[UITableView alloc] initWithFrame:CGRectMake(0, 80, self.view.frame.size.width,self.view.frame.size.height) style:UITableViewStylePlain]; 但是你需要为你的tableview创建一个outlet来 ...