Tag: uitableview

3D从UITableViewCell触摸Peek和Pop如何将数据交给其他UIViewController?

我的应用程序在Core Data对象中存储不同的属性。 它们都显示在一个UITableView中,如果你点击一个单元格,就会显示一个DetailView。 像Master-Detail-XCode-Template一样。 现在我想用peek和pop来实现3D Touch。 就像在邮件应用程序中,3D触摸一个单元格,获得预览,按下更深,popup细节。 到目前为止,我已经得到了这个工作,但我无法弄清楚如何传递相应的数据 – (nullable UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location 和 – (void)previewingContext:(id <UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit 到另一个DetailViewController。 如果你只是点击单元格(没有3D触摸),我交出数据 – (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath]; [[segue destinationViewController] setDetailItem:object]; 我正在使用一个 id detailItem 在每个ViewController中,我将相应的对象设置为它。 所以我尝试了类似的工作,所以在我的DetailViewController我的“detailItem”需要从选定的(3D触摸)单元格相应的核心数据对象。 感谢帮助 !

在UITableView后面设置渐变

我创build了一个tableViewController我调用这个函数: func setTableViewBackgroundGradient(sender: UITableViewController ,let topColor:UIColor, let bottomColor:UIColor){ let gradientBackgroundColors = [topColor.CGColor, bottomColor.CGColor] let gradientLocations = [0.0,1.0] let gradientLayer = CAGradientLayer() gradientLayer.colors = gradientBackgroundColors gradientLayer.locations = gradientLocations gradientLayer.frame = sender.tableView.bounds sender.tableView.backgroundView?.layer.insertSublayer(gradientLayer, atIndex: 0) } 有: setTableViewBackgroundGradient(self, UIColor(0xF47434), UIColor(0xEE3965)) 但我得到的是这样的:

如何在iOS的uitableview中使用可重用的单元格

好。 我似乎对桌面的工作方式有了一个明确的理解。 有人请向我解释如何在桌面浏览器中重复使用单元格,特别是在滚动时? 我对此有一个主要的难点,就是当我在一个单元格中创build一个动作时,其他单元格会在我滚动时受到影响。 我试图使用一个数组作为模型的后端,但我仍然得到单元格,当没有设想。 要弄清楚的是,为什么当数组中的模型没有改变时,它们会发生改变。 一个简单的例子: 使用“like”button的表格视图单元格。 当我单击其中一个单元格中的button时,button文本更改为“不同”(到目前为止这么好)。 但是当我向下滚动时,其他单元格也显示“不同”,即使我没有select它们。 而当我向上滚动时,我原来select的单元格又改变了,新的单元格也改变了。 我似乎无法弄清楚这一点。 如果你能给我看一个可用的示例源代码,那将是非常棒的! 谢谢! – (void)viewDidLoad { [super viewDidLoad]; likeState = [[NSMutableArray alloc]init]; int i =0; for (i=0; i<20; i++) { [likeState addObject:[NSNumber numberWithInt:0]]; } } – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [myButton setTitle:@"Like" […]

粘滞的search栏和节标题行为类似于本机通讯录应用程序

我想在iPhone联系人应用程序中复制search栏的粘性行为。 当用户向下滚动视图时, search栏也随着视图一起下移 : 如果用户向上滚动,则表格相应地滚动,具有以下两种行为: (1)search栏保持固定在顶部 ,并且 (2) 后面的部分标题在search栏下方正确停止 : 当下一节标题出现时,前面的标题在search栏下消失: 注意:段落索引控件(右侧的az)也出现在search栏的顶部 。 Ergo,摆弄contentInset会把它的索引控件一起向下推。 我创build了一个自定义UIViewController ,添加了一个UITableView ,将其contentInset设置为search栏的高度。 我创build了一个UIView ,添加了search栏作为它的子视图,然后将UIView添加到UITableView 。 但是,如上所述,当用户滚动时,节标题仍然保持在零位,而不是在标题高度。 此外,节标题索引控制​​位置受到不利影响。 我会很感激解决这个问题。

展开和折叠tableview单元格

我能够展开和折叠单元格,但是我想调用UITableViewCell中的函数(展开和折叠)来改变button标题。 导入UIKit 类MyTicketsTableViewController:UITableViewController { var selectedIndexPath:NSIndexPath? var extraHeight:CGFloat = 100 重写func viewDidLoad(){ super.viewDidLoad() } 覆盖func didReceiveMemoryWarning(){ super.didReceiveMemoryWarning() //处理任何可以重新创build的资源。 } 重写func tableView(tableView:UITableView,numberOfRowsInSection部分:Int) – > Int { 返回5 } 重写func tableView(tableView:UITableView,cellForRowAtIndexPath indexPath:NSIndexPath) – > UITableViewCell { 让cell = tableView.dequeueReusableCellWithIdentifier(“cell”,forIndexPath:indexPath)as! MyTicketsTableViewCell 返回单元格 } 重写func tableView(tableView:UITableView,heightForRowAtIndexPath indexPath:NSIndexPath) – > CGFloat { if(selectedIndexPath!= nil && indexPath.compare(selectedIndexPath!)== NSComparisonResult.OrderedSame){ 返回230 + extraHeight […]

如何使用UIScrollView或UITableView来devise和创build一个GridView

我认为在许多情况下GridView是一个非常普遍的观点。 作为iOS的初学者,我只是想知道为什么iOS没有提供一个GridView类。 所以这里是我的问题,如何devise和使用UIScrollView或UITableView创build一个GridView? 还是有一些其他的解决scheme来创build一个GridView感谢您的答案。

如何同时更新每个自定义tableview单元格数据?

我正在使用Swift 3的Xcode 8.2.1。我有一个自定义UITableViewCell包含UITextView。 当我inputtextView ,自定义单元格自动增长。 这部分工作正常。 我还想在input特定的单元格时使用相同的数据更新我的其他单元格。 例如: 当我在第五个单元格中键入文本时,在第十一,十五和十八个单元格中自动input相同的数据。 那些细胞也必须自动生长。 我已经将数据添加到数组的特定索引。 但是它并没有反映在tableView 。 我如何实现这个function? 请通过以下代码我已经实现到目前为止。 这个updateCellHeight方法是一个自定义的委托方法。 这个方法在用户inputtextView时候被调用。 func updateCellHeight(indexPath: IndexPath, comment: String) { let currentCellLyricVal = self.traduzioneArray[indexPath.row]["rics"] tempIndexArray.removeAll() for (index,element) in traduzioneArray.enumerated() { let lyricVal = element["rics"] if currentCellLyricVal == lyricVal { tempIndexArray.append(index) } } for index in tempIndexArray { self.traduzioneArray[index]["ione"] = comment self.lyricsTableView.beginUpdates() self.lyricsTableView.endUpdates() […]

indexPathForSelectedRow返回nil

我有一个UIVableViewController与我试图得到当前选定的行的segue: -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if([[segue identifier] isEqualToString:@"EditFilterElementSegue"]){ // Get the element that was clicked and pass it to the view controller for display NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow]; Element *element = [fetchedResultsController objectAtIndexPath:selectedIndexPath]; FilterElementTableViewController *vc = segue.destinationViewController; vc.filter = filter; vc.element = element; } } 问题是indexPathForSelectedRow返回nil。 文档说,如果索引path无效,返回nil。 如果我添加: [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:0]; selectedIndexPath […]

'必需的'初始化'init(coder :)'必须由'UITableViewCell'`的子类提供

据说这个代码在这里和这里工作 ,但我似乎无法使其工作。 IBOutlets连接到故事板中的对象。 prototypeCell被命名,所以我可以使用它与dequeueReusableCellWithIdentifier和它的自定义类属性设置为commentCell 。 第一个错误(我可以解决,但上面的链接都不需要它,这让我觉得我做错了什么,对吗?): Overriding method with selector 'initWithStyle:reuseIdentifier:' has incompatible type '(UITableViewCellStyle, String) -> commentCell' 第二个错误(有趣的错误): 'required' initializer 'init(coder:)' must be provided by subclass of 'UITableViewCell'` 单元分类代码: class commentCell: UITableViewCell { @IBOutlet weak var authorLabel: UILabel! @IBOutlet weak var commentLabel: UITextView! init(style: UITableViewCellStyle, reuseIdentifier: String) { super.init(style: style, reuseIdentifier: reuseIdentifier) } override […]

在性能问题之前调用UITableView中所有行和多less行的heightForRowAtIndexPath?

我以为我读了一个UITableView heightForRowAtIndexPath不会被所有行调用,但只有那些将是可见的。 这不是我所看到的。 例如,我看到数百个针对iPhone的方向被改变的简单情况的heightForRowAtIndexPath调用。 所以我在这里假设,因此,对于一个UITableView与heightForRowAtIndexPath实现,它((即heightForRowAtIndexPath )被调用的所有行(不只是可见的)…让我知道如果这是不正确的。 问题:鉴于上述情况,通常会出现性能问题之前, UITableView中有多less行(其中实现了heightForRowAtIndexPath )? 有没有解决性能问题的方法? 即设置一个名义/标准高度的每一行,而不是实现heightForRowAtIndexPath ,但然后正确地设置每个行的高度,只有当它被显示,并在这里设置正确…但是哪种方法可以做到这一点?