Tag: uitableview

在视图控制器之间传递数据:从uitableview到详细信息视图控制器

我正在使用IOS 5和故事板编码。 我已经build立了一个应用程序,我有一个tableView连接到一个search栏的SQLite数据库。 当我们触摸一行时,它会自动将我们带到另一个名为“Details”的视图控制器。 我需要将数据从我的表视图传递给详细信息视图控制器,例如将author.title传递给labelText.text字段。 有任何想法吗? 编辑的问题: – (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ // NSString *Title; Details *dv = (Details*)segue.destinationViewController; author.title = dv.labelText.text; } 部分代码: // // Details.m // AuthorsApp // // Created by georges ouyoun on 7/17/12. // Copyright (c) 2012 __MyCompanyName__. All rights reserved. // #import "Details.h" #import "Author.h" @interface Details () @end @implementation Details […]

发现检测buttoncellForRowAt

我需要检测在UITableViewController中是否点击了button override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let LikesBtn = cell.viewWithTag(7) as! UIButton }

在TableViewCell里面的UICollectionView没有被调用

我有一个UITableView包含一个水平滚动UICollectionView在这样的每个单元格 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ServiceTypeCell cell.collectionView.delegate = self cell.collectionView.dataSource = self cell.lblName.text = serviceTypes[indexPath.row].name cell.tag = getTag(indexPath) print("uitableviewcell : \(indexPath)") return cell } 并在每个UICollectionViews func numberOfSections(in collectionView: UICollectionView) -> Int { return 1 } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection […]

如何在滚动tableview后点击select行来修复崩溃?

我有这样的表格视图: 当用户点击一行时,我想取消选中最后一行并检查选中的行。 所以我这样写我的代码:(例如我的lastselected = 0) func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { var lastIndexPath:NSIndexPath = NSIndexPath(forRow: lastSelected, inSection: 0) var lastCell = self.diceFaceTable.cellForRowAtIndexPath(lastIndexPath) as! TableViewCell var cell = self.diceFaceTable.cellForRowAtIndexPath(indexPath) as! TableViewCell lastCell.checkImg.image = UIImage(named: "uncheck") cell.checkImg.image = UIImage(named: "check") lastSelected = indexPath.row } 当我点击一行而不滚动时,每件事情都很好。 我意识到,当我运行的代码和滚动表立即select了一行。 我的程序会崩溃,错误:“致命错误:意外地发现零,而解包可选值” 错误显示在这一行: 我不知道这里有什么错

在模拟器中表格视图的起始位置是错误的,而在故事板中是不一样的

我在storyboard中创build了一个tableview,看起来不错,但是模拟器或者设备的起始位置是错误的。 “标签”不应该与时间相同。 我怎么能解决它?

在UITableView原型中包含图像的UICollectionView单元格

更新:我解决了我的主要问题正确的图像不加载,直到滚动collectionView。 我添加了一个collectionView.reloadData()到tableView:cellForRowAtIndexPath。 我也做了一些修改来预加载序列数组,而不是在滚动表(tableView:cellForRowAtIndexPath)的时候创build它。 如果您有兴趣,可以将更新添加到GitHub。 https://github.com/Druiced/OpenDeck 一旦我找出如何防止应用程序崩溃,当dynamic值被放置在返回(如果我将其设置为15,应用程序不会崩溃),我会后续: func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return count(Array(sequenceArray[collectionView.tag])) / 2 } 原来的post:请求一些指导。 本教程帮助我意识到这必须与我的DataSource / Delegate有关。 作者使用addSubview构build单元格,而不是利用Xcode原型单元格,这似乎是一件很酷的事情,所以我正在尝试这样做。 http://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell 任何批评我的做法或不遵循最佳做法是值得欢迎的。 表中的每个单元格都有一个UICollectionView。 集合视图中的每个单元格按保存的“序列”string的顺序显示图像。 例如:“ADKDQDJDTD”链接到AD.png KD.png QD.png JD.png TD.png 我有两个问题,我似乎无法通过。 numberOfItemsInSection当卡数由数组长度驱动(返回handArray.count / 2)时会变得怪异。 如果我放置一个固定的号码应用程序将工作,但不是很光滑。 桌子第一次出现时,正确的牌不会显示,直到我上下滚动桌子。 它也显示每个CollectionView的数据是交叉的path,因为当快速上下滚动时显示错误的卡片。 我几乎肯定这与我的数据源是如何设置的。 DeckTableViewController.swift import UIKit import Parse var deviceID: String? var noRefresh: Bool? var sequenceArray: […]

UITableViewCell initWithStyle:UITableViewCellStyleSubtitle不起作用

我在尝试在单元格中显示信息时遇到问题,一个在左侧,另一个在右侧。 我知道与UITableViewCellStyleSubtitle使用initWithStyle 。 我用这个,但似乎没有工作。 这是一些示例代码: – (UITableViewCell *)tableView:(UITableView *)ltableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Account Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:Cellidentifier]; } Accounts *account = [self.fetchedResultsController objectAtIndexPath]; cell.textLabel.text = account.name; cell.detailTextLabel.text = @"Price"; return cell; } 我可以显示cell.textLabel.text很好,但是我不能得到简单的“价格”显示。 我尝试了不同的东西,比如设置cell.detailTextLabel的字体大小。 我也尝试了一些UITableViewCellStyleValue1在老职位中的build议。 将NSLog设置为“Price”后,将cell.detailTextLabel显示为null。 不知道我在做什么错。 编辑:我发现这个: […]

迭代所有的UITableCells给出一个部分ID

我如何迭代所有的UITableCells给出一个部分ID(例如:第2节中的所有单元格)? 我只看到这个方法: tableView.cellForRowAtIndexPath ,它返回给定的绝对索引1单元格,所以它没有帮助。 有没有一个优雅和简单的方法? 注意:我想以段落中的所有单元格为单位设置AccesoryType为None,例如:在单击button之后,或者在发生事件之后(发生什么事情与问题无关) 我有UITableView的参考和部分的索引。

坚持UITableView标题视图顶部时,故事板中创build标题

我使用这里的答案创build了一个表视图标题。 我的问题是,当以这种方式创build头时,它不会“粘”到我的UITableView的顶部向下滚动。 如果我在viewForHeader内的代码中创build我的头,那么它坚持。 如果我在故事板中创build它,我怎样才能让我的标题在滚动时保持顶部? 另外两个人在这里和这里问这个问题,从来没有得到答案。 是的,我的UITableView已经是普通的风格,没有分组。

indexPathForRowAtPoint只返回一个uitableview中的第一个单元格

我有一个UIButton在自定义的UITableViewCell里面,按下button时删除单元格。 为了获得button所在的单元格的indexPath,我调用indexPathForRowAtPoint :在按下button时调用的方法如下: -(void)buttonPressed:(UIButton *)sender{ CGPoint btnPosition = [sender convertPoint:CGPointZero toView:self.tableView]; NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:btnPosition]; if (indexPath != nil) { //remove the cell from the tableview. } } 这工作正常,如果我按下除第一个单元格以外的任何单元格中的button,以及如果表格中只有一个单元格时。 但是,如果有多个单元格,并按下第一个单元格中的button,触发buttonbutton,并findbtnPosition,但[self.tableView indexPathForRowAtPoint:btnPosition]; 返回nil 。 例如,如果有三个单元格,每个单元格都有一个button: 我按下第一个单元格button: buttonPressed被调用,但indexPath是零,所以没有任何反应。 我按下第三个单元格button: buttonPressed被调用,并按预期删除单元格。 我再次按下第一个单元格: 与之前一样,buttonPressed调用但indexPath为零。 我按下第二个单元格button: buttonPressed被调用,单元格按预期被删除。 我按下第一个单元格button: 这一次,调用buttonPressed,indexPath不是零,并按预期删除单元格。 我已经检查过,tableView并不是零,正如相关但不同的post所build议的那样。 我也已经证实,当[self.tableView indexPathForRowAtPoint:btnPosition] == nil AND [self.tableView indexPathForRowAtPoint:btnPosition] != nil时,点btnPosition被设置为相同的值(x=260, […]