- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 TableView 和一个与导航 Controller 连接的详细 View Controller ,当我按下它时,它会转到详细 View Controller ,它在我的详细 View Controller 中工作正常我有一个按钮我想要在按下该按钮后隐藏我单击的特定单元格。我正在使用 Swift 3 Xcode 8。
表格 View :
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource{
var delegate = SimpleProtocol.self
@IBOutlet weak var tableview: UITableView!
var cars = ["Ferrari", "Lamborghini", "Aston Martin", "Buggati", "Tesla"]
var carslogo = ["images-7", "photo", "astonmartinlogo", "buggatilogo", "Tesla-Motors-logo-3"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
tableview.dataSource = self
tableview.delegate = self
tableview.contentInset = UIEdgeInsets(top: 0,left: 0,bottom: 0,right: 0)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
tableview.reloadData()
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 150.0
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return cars.count
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let indexPath = tableView.indexPathForSelectedRow!
self.performSegue(withIdentifier: "ss", sender: indexPath)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "ss" {
let details = segue.destination as! DetailViewController
let indexPath = sender as! IndexPath
details.view1 = cars[indexPath.row]
details.view3 = UIImage(named: cars[indexPath.row])!
if indexPath.row == 0 {
details.view2 = ("Ferrari N.V. pronounced ferˈrari is an Italian sports car manufacturer based in Maranello. Founded by Enzo Ferrari in 1939 out of Alfa Romeo's race division as Auto Avio Costruzioni, the company built its first car in 1940. However the company's inception as an auto manufacturer is usually recognized in 1947, when the first Ferrari-badged car was completed.In 2014, Ferrari was rated the world's most powerful brand by Brand Finance. In May 2012 the 1962 Ferrari 250 GTO became the most expensive car in history, selling in a private transaction for US$38.1 million to American communications magnate Craig McCaw.Fiat S.p.A. acquired 50 percent of Ferrari in 1969 and expanded its stake to 90 percent in 1988.[5] In October 2014 Fiat Chrysler Automobiles announced its intentions to separate Ferrari S.p.A. from FCA; as of the announcement FCA owned 90 percent of Ferrari. The separation began in October 2015 with a restructuring that established Ferrari N.V. (a company incorporated in the Netherlands) as the new holding company of the Ferrari group and the subsequent sale by FCA of 10 percent of the shares in an IPO and concurrent listing of common shares on the New York Stock Exchange. Through the remaining steps of the separation, FCA's interest in Ferrari's business was distributed to shareholders of FCA, with 10 percent continuing to be owned by Piero Ferrari. The spin-off was completed on 3 January 2016.")
} else if indexPath.row == 1 {
details.view2 = ("The Lamborghini Aventador is a mid-engined sports car produced by the Italian manufacturer Lamborghini.Launched on 28 February 2011 at the Geneva Motor Show, five months after its initial unveiling in Sant'Agata Bolognese, the vehicle, internally codenamed LB834, was designed to replace the then-decade-old Murciélago as the new flagship model.Soon after the Aventador unveiling, Lamborghini announced that it had already sold over 12 of the production vehicles, with deliveries starting in the second half of 2011. By March 2016, Lamborghini had already built 5,000 Aventadors, taking five years to achieve this milestone.")
} else if indexPath.row == 2 {
details.view2 = ("Aston Martin Lagonda Limited is a British manufacturer of luxury sports cars and grand tourers. It was founded in 1913 by Lionel Martin and Robert Bamford. Steered from 1947 by David Brown it became associated with expensive grand touring cars in the 1950s and 1960s, and with the fictional character James Bond following his use of a DB5 model in the 1964 film Goldfinger. Their sports cars are regarded as a British cultural icon. Aston Martin has held a Royal Warrant as purveyor of motorcars to HRH the Prince of Wales since 1982.Headquarters and the main production site are in Gaydon, Warwickshire, England, on the site of a former RAF V Bomber airbase. One of Aston Martin's recent cars was named after the 1950s Vulcan Bomber. Aston Martin has diversified to speed boats, and real estate development.")
} else if indexPath.row == 3 {
details.view2 = ("Automobiles Ettore Bugatti was a French car manufacturer of high-performance automobiles, founded in 1909 in the then German city of Molsheim, Alsace by Italian-born Ettore Bugatti. Bugatti cars were known for their design beauty (Ettore Bugatti was from a family of artists and considered himself to be both an artist and constructor[clarification needed]) and for their many race victories. Famous Bugattis include the Type 35 Grand Prix cars, the Type 41 Royale, the Type 57 Atlantic and the Type 55 sports car. The death of Ettore Bugatti in 1947 proved to be the end for the marque, and the death of his son Jean Bugatti in 1939 ensured there was not a successor to lead the factory. No more than about 8,000 cars were made. The company struggled financially, and released one last model in the 1950s, before eventually being purchased for its airplane parts business in the 1960s. In the 1990s, an Italian entrepreneur revived it as a builder of limited production exclusive sports cars. Today, the name is owned by German automobile manufacturing group Volkswagen.")
} else if indexPath.row == 4 {
details.view2 = ("Tesla, Inc. (formerly named Tesla Motors) is an American automaker, energy storage company, and solar panel manufacturer based in Palo Alto, California.[7] The company was initially founded in 2003 by Martin Eberhard and Marc Tarpenning, although the company also considers Elon Musk, JB Straubel, and Ian Wright as its co-founders. The company specializes in electric cars, lithium-ion battery energy storage, and, through their SolarCity subsidiary, residential solar panels. Tesla first gained widespread attention following production of the Roadster, the first electric sports car, in February 2008. The companys second vehicle, the Model S, an electric luxury sedan, debuted in June 2012 and is built at the Tesla Factory in California. The Model S has been the world s best-selling plug-in electric car for two years in a row, 2015 and 2016. Its global sales achieved the 150,000 unit milestone in November 2016, four years and five months after its introduction. As of December 2016, the Model S ranks as the world's all-time second best-selling plug-in after the Nissan Leaf.")
}
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableview.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TableViewCell
let name = cars[indexPath.row]
let logonmae = carslogo[indexPath.row]
cell.label.text = name
cell.logoimage.image = UIImage(named: logonmae)
cell.image1.image = UIImage(named: name)
return cell
}
}
详细 View Controller :
class Model: Object {
dynamic var carname : String?
dynamic var detail : String?
}
class DetailViewController: UIViewController {
let object = ViewController()
let ob = TableViewCell()
var model : Model?
let realm = try! Realm()
@IBOutlet weak var detailimage: UIImageView!
@IBOutlet weak var detaillabel: UILabel!
@IBOutlet weak var detailtextfield: UITextView!
@IBAction func button(_ sender: Any) {
self.model = Model()
model!.carname = self.detaillabel.text!
model!.detail = self.detailtextfield.text!
if let data = model {
try! self.realm.write {
self.realm.add(data)
}
}
}
var view1 = ""
var view2 = String()
var view3 = UIImage()
override func viewDidLoad() {
super.viewDidLoad()
detaillabel.text = view1
detailtextfield.text = view2
detailimage.image = view3
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
最佳答案
据我推断,您的详细 View Controller 上有一个按钮,按下该按钮后您想要删除当前详细 View Controller 所在的单元格。
您的方法应该是当您在 detail view controller
中时,您应该传递您来自的单元格的 index
。
现在,当用户单击按钮时,您可以使用一个 bool
来检查或传回您的 TableView 。
当用户单击按钮并返回表格时,您实际上应该同时传递索引和标志,然后在您的 tableview 类的viewwillappear
中,您可以根据标志检查是否应该删除所选索引,如果索引设置为删除,那么您应该简单地使用索引从 cars
和 cars-logo array
和reload
你的tableview。
这些可以改进很多,但这应该足以作为起点。
关于ios - 在 swift 3 中删除 TableView 的特定选择单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45592551/
我正在对 tableView 是否呈现单元格进行单元测试。 我发现 tableView.cellForRow(at:) 返回 nil,而 tableView.dataSource?tableView(
我有 Tableview 用于显示客户下的食品订单。其中包含水平 UIStackview。在 UIStackView UIStackview 中很少有一/两行标签和一个用于显示订单项的UITableV
我有 Viewcontroller,我在其中设置了 ScrollView 。在 scrollview 中,我有一个 tableview,它位于 Container 中,就在容器下方,当我将 table
我想在滚动时让我的第一个单元格始终位于 tableview 的顶部。 任何帮助都是可观的。提前致谢... 最佳答案 这是为 UITableView 创建标题 View 的方法 - (UIView *)
在我的应用程序中,我点击一行,它会在其下方展开另一行。我想生成一种随机颜色,当我单击一行时,行背景会变成该颜色,而它下面的展开行会变成相同的颜色。如何让行生成相同的随机颜色? 我创建了一个函数来生成随
我正在为这个问题苦苦挣扎,所以我需要你的帮助。基本上我已经编写了一个复杂的 TableView Controller (使用 NSFetchedResults 协议(protocol)等)并且已经在我
我正在使用 JavaFx 2.2。我遇到了一个问题,我无法在 TableView 列中放置不同的组件。例如我有两列 1) 回答 2) 答案类型 如果 AnswerType 包含“Multiple Ch
试图弄清楚如何在 javafx 2 中禁用表列的重新排序? 最佳答案 这是解决方案: tblView.getColumns().addListener(new ListChangeListener()
我一直在寻找有关将数据刷新到 tableview 的信息。我试图直接修改模型,但我遇到了一个错误。我修改了模型,但表格没有刷新,只有当我移动一列时,表格才会显示修改后的值。 为了给你展示一个例子(13
给定一个TableView,我需要检测单元格上的双击。 tableView.setOnMouseClicked(new EventHandler() { @Override publi
我成功创建了一个 TableView,其中将特定列分配给了数据模型类。该程序可以将 csv 文件解析为其中并在表中正确显示所有内容。在此阶段,滚动不是问题。 然后我想选择特定行并将它们发送到另一个表。
我尝试了所有方法来用数据填充 TableView。下一个代码在表中插入一个新行,但数据没有出现在表中。我试图为此找到解释,但没有成功。 请帮忙。我不知道怎么了。 在 controller.java 中
我尝试了所有方法来用数据填充 TableView。下一个代码在表中插入一个新行,但数据没有出现在表中。我试图为此找到解释,但没有成功。 请帮忙。我不知道怎么了。 在 controller.java 中
我有一个通过 Tableview 显示玩家的应用程序。用户可以“添加”一个新玩家并输入他的姓名、高度、体重、图片等...保存后将被添加到 Tableview 中。他们还可以点击每个玩家,然后将他们带到
对于大学,我必须编写一个小应用程序,其想法是创建一个小公式集合。这个概念是有一个类别列表,选择类别后您会收到一个公式列表。选择所需的公式后,您将看到公式计算器的 View 。 我正在努力获得第一个UI
如果我只加载一个 TableView ,我的 View 中必须有两个 TableView ,它工作正常。但是当我尝试使用下面的方法加载两个表格 View 时,它给出了以下异常。 未捕获异常“NSRan
我是 JavaFx 的新手,我正在尝试创建一个 TableView ,而 fxml 是使用场景生成器创建的。如果我运行该程序,该表不会获取值。我发现这个问题在某种程度上符合我的要求( javaFX 2
是否可以对 tableView 进行反向排序?我搜索了很多解决方案,但没有任何效果。 效果就像whatsapp聊天。 一个普通的tableView是: ---------- label 1 -----
我有一个有趣的问题。我有两个 TableView ,一个在另一个里面。我有一个结构,我想用它来将数据添加到我的 TableView 中。该结构有 2 个字符串项和另一个具有 3 个字符串项的结构的数组
我正在使用的方法 func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath
我是一名优秀的程序员,十分优秀!