标签: tableviewcell

TableView - 编辑聚焦单元格

我有一个侦听键盘事件的事件监听器.当我尝试使用键事件进入编辑模式时,由于某些奇怪的原因,不正确的单元格进入编辑模式.

例如,我想编辑一个单元格.我使用键盘箭头转到我想要编辑的单元格,即聚焦的单元格.通过单击键盘上的字母,焦点单元格应进入编辑模式.当我尝试编辑聚焦单元格时,错误的单元格进入编辑模式.

private final class EditCell extends TableCell<SimpleStringProperty, String> implements GenericTable
{

    public EditCell()
    {
        // Add event listsner. table is a TableView
        table.setOnKeyPressed(keyEvent -> this.handleKeyPressed(keyEvent));
    }

    public void handleKeyPressed(KeyEvent key)
    {
        // Keyboard events
        if (key.getCode().isLetterKey())
        {
            if (!this.isEditing())
            {

                this.edit = true;

                // focus index
                int focusIndex = this.table.getSelectionModel().getFocusedIndex();

                this.changeTableCellFocus(this.table, focusIndex);

                this.startEdit();
            }
        }
    }


    // startEdit() function
    @Override
    public void startEdit()
    {
        if (this.edit)
        {
            LOGGER.info("Start editing on cell index: " + this.getIndex());
            super.startEdit();
            this.createTextField();
            this.setText(null);
            this.setGraphic(this.textField); …
Run Code Online (Sandbox Code Playgroud)

java javafx focus tableviewcell

1
推荐指数
1
解决办法
4982
查看次数

如何在结束显示时更改CustomCell?

我想更改此代码:

override func tableView(tableView: UITableView, didEndDisplayingCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

}
Run Code Online (Sandbox Code Playgroud)

像那样:

override func tableView(tableView: UITableView, didEndDisplayingCell cell: CustomCell, forRowAtIndexPath indexPath: NSIndexPath) {

}
Run Code Online (Sandbox Code Playgroud)

但是我收到一条错误消息.当它消失时,我需要更改我的CustomCell.我怎么处理这个?

custom-cell tableviewcell swift

1
推荐指数
1
解决办法
1338
查看次数

在uitableview中选择时更改自定义单元格图像颜色?

我有一个带有imageview和label的自定义单元格.当用户在tableview中选择一个特定单元格时,我想要更改图像颜色或色调.我设法改变了标签的颜色,但不知道如何处理图像.有任何想法吗?

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

         static NSString *CellIdentifier = @"MenuCell";

        MenuTableViewCell *cell = (MenuTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {

            cell = [[MenuTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
           // cell.selectionStyle = UITableViewCellSelectionStyleNone;

        }


        cell.lblTitle.text = [[_items objectAtIndex:[indexPath row]] valueForKey:@"title"];
        cell.imgIcon.image = [UIImage imageNamed:[[_items objectAtIndex:[indexPath row]] valueForKey:@"image"]];
        cell.lblTitle.highlightedTextColor = [UIColor colorWithRed:0.839 green:0.682 blue:0.047 alpha:1];
       cell.selectionStyle = UITableViewCellSelectionStyleGray;
        return cell;
    }
Run Code Online (Sandbox Code Playgroud)

谢谢

objective-c uitableview uiimage tableviewcell ios

1
推荐指数
1
解决办法
4319
查看次数

为什么没有调用didDeselectRowAtIndexPath

调用didSelectRowAtIndexPath,但未调用didDeselectRowAtIndexPath.我不是为什么.我在线搜索.很多类似的问题,但我找不到答案.

这是我的桌面视图

//tableView
    let tempTableView = UITableView()
    tempTableView.delegate = self
    tempTableView.dataSource = self
    tempTableView.translatesAutoresizingMaskIntoConstraints = false
    self.view.addSubview(tempTableView)
    self.tableView = tempTableView
Run Code Online (Sandbox Code Playgroud)

这是代表

 //MARK: UITableViewDelegate
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

   self.cayegoryArray[indexPath.row].isSelected = true
   self.tableView?.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.None)

}

func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {

    self.cayegoryArray[indexPath.row].isSelected = false
    self.tableView?.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.None)
}
Run Code Online (Sandbox Code Playgroud)

这是细胞.

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)

    self.selectionStyle = .Default

    setInterface()
    setLayout()
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not …
Run Code Online (Sandbox Code Playgroud)

iphone uitableview tableviewcell ios

1
推荐指数
1
解决办法
1892
查看次数

禁用单元格滑动操作

所以我有一个应用程序(用Swift编写),允许用户在searchController中搜索高尔夫球场.然后他们可以选择该课程,然后选择的课程进入tableView.我正在为搜索控制器和所选课程列表使用相同的视图控制器.

我遇到的问题是我希望用户能够滑动以删除他们选择的课程,但不是在搜索控制器处于活动状态时填充搜索控制器的课程.滑动删除操作正在常规tableView中工作.当searchController处于活动状态时,我将其置于禁用删除按钮的位置.但是,如果searchController处于活动状态,我想要做的就是没有单元格能够完全滑动.似乎无法让它发挥作用.有什么建议?谢谢,麻烦您了.

这是我的代码:

 override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {

    if searchController.active {

    UITableViewCellEditingStyle.None

    } else {

    let deletedValue = previousCoursesFromRealm[indexPath.row]

    if editingStyle == UITableViewCellEditingStyle.Delete {
        let realm = try! Realm()
        try! realm.write {
        realm.delete(deletedValue)
        }

     coursesTableView.reloadData()

     }
    }
   }  
Run Code Online (Sandbox Code Playgroud)

uitableview tableviewcell swift edit-tableview

1
推荐指数
1
解决办法
3312
查看次数

满足条件后如何在swift中停止活动指示器?

我已经在我的模型的扩展中声明了一个UIActivityIndi​​catorView作为计算属性.我有一个方法configureCell,我正在尝试使用活动指示器作为imageView的子视图.在这里,我能够将指标置于特定条件下,但以后无法对其进行任何更改.例如,我无法停止活动指示器,无法更改颜色,甚至无法隐藏它.

extension TranscationModel: UITableViewDataSource, UITableViewDelegate
{

 var activityIN: UIActivityIndicatorView {
    var act = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)
    act.color = UIColor.redColor()
    act.hidden = false
    act.startAnimating()
    return act
}

func configureTransactionCell(cell : TransactionCell?, indexPath: NSIndexPath) {
    if transaction.tid == "Something" {
        activityIN.color = UIColor.greenColor() //Even this doesn't work
        activityIN.center = cell.imgTransactionBill.center
        cell.imgTransactionBill.addSubview(activityIN)
        let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(10 * Double(NSEC_PER_SEC)))
        dispatch_after(delayTime, dispatch_get_main_queue()) {
             activityIN.stopAnimating() //Not working
             activityIN.hidden = true   //Not working
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

uiactivityindicatorview tableviewcell ios swift

1
推荐指数
1
解决办法
2919
查看次数

快速获取另一个 ViewController 中选定单元格的数据(以编程方式)

这个问题已经回答过很多次了。但是我能找到的答案对我不起作用,因为我似乎无法调用单元格的类。

进一步解释:

我有一个带有 UITable 的 viewController。单元格在 UITableViewCell 类中配置。(我需要从这个类中提取信息)

我的“细胞类”被称为 mySuggestionsCel

这是我的“didSelectRowAtIndexPath”代码

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    tableView.allowsSelection = false

    var selectedCell:UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!

    var VC = detaiLSuggestion_VC()
    self.navigationController?.pushViewController(VC, animated: true)


    if selectedCell.backgroundColor == UIColor.formulaFormColor() {
        selectedCell.backgroundColor = UIColor.formulaMediumBlue()
        UIView.animateWithDuration(0.5, animations: {
            selectedCell.backgroundColor = UIColor.formulaFormColor()
        })
    } else {
        selectedCell.backgroundColor = UIColor.formulaGreenColor()
        UIView.animateWithDuration(0.5, animations: {
            selectedCell.backgroundColor = UIColor.formulaLightGreenColor()
        })
    }
}
Run Code Online (Sandbox Code Playgroud)

我试着做

mySuggestionsCell.someVariable

我也试过 selectedCell.someVariable

都没有工作。

我需要从我的单元格类中的 detailSuggestion_VC() 中获取此信息。但是它需要提取的数据是被选中的特定单元格的数据。这就是为什么我在让它工作时遇到了一些麻烦。

我环顾了一会。但是找不到这个特定问题的任何问题或答案。

任何帮助将不胜感激

uitableview tableviewcell ios swift

0
推荐指数
1
解决办法
4609
查看次数

swift detailTextLabel没有显示出来

我已经检查了stackOverFlow的解决方案,但它似乎仍然没有为我的代码工作..我的detailTextLabel仍然没有显示:(

想知道我做错了什么,这是我的代码

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell = UITableViewCell()
    // display our ranked data
    cell.textLabel?.text = "\(championListInGame[indexPath.row])"

    if let url = NSURL(string: "http://ddragon.leagueoflegends.com/cdn/img/champion/loading/\(championListInGame[indexPath.row])_0.jpg"){
        if let urlData = NSData(contentsOfURL: url){
            cell.imageView?.contentMode = UIViewContentMode.ScaleAspectFit
            cell.imageView?.image = UIImage(data: urlData)
        }
    }

    if victory[indexPath.row] == true {
        cell.backgroundColor = UIColor.blueColor()
        cell.detailTextLabel?.text = " "+"victory!"
    } else {
        cell.backgroundColor = UIColor.redColor()
        cell.detailTextLabel?.text = " "+"defeat!"
    }

    return cell
}
Run Code Online (Sandbox Code Playgroud)

然而,我的胜利和失败都出现在我的桌子中,颜色,图像和文字都像我想要的那样出现.

在旁注,有人可以教我如何选择婴儿蓝或婴儿红等颜色?默认的红色和蓝色对我的应用来说太强了:(

谢谢你的帮助!

colors tableviewcell swift

0
推荐指数
1
解决办法
2720
查看次数

IBoutlet在我的自定义表格单元格中是否为零?

//自定义单元格在一个swift文件中

import UIKit

class CardTableViewCell: UITableViewCell {

    @IBOutlet weak var elapsedTime: UILabel!
    @IBOutlet weak var todo: UILabel!
    @IBOutlet weak var startAndStop: UIView!
    @IBOutlet weak var progress: UIView!
    @IBOutlet weak var cardView: UIView!

}
Run Code Online (Sandbox Code Playgroud)

//自定义表视图控制器在另一个swift文件中

import UIKit

class CardFeedTableViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.register(CardTableViewCell.self, forCellReuseIdentifier: "cardCell")
        tableView.delegate = self
        tableView.dataSource = self
    }

    // MARK: - Table view data source

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number …
Run Code Online (Sandbox Code Playgroud)

uitableview custom-cell tableviewcell ios swift

0
推荐指数
1
解决办法
1497
查看次数

如何快速显示和隐藏表格视图单元格

我有一个带有两个不同自定义单元格的 tableView。一个单元格的文本字段数据很少,其他单元格也有不同的文本字段数据,在这里我需要折叠并隐藏每个单元格。我不知道该怎么做。请告诉我。

https://maniacdev.com/2013/03/an-open-source-ios-control-allowing-you-to-create-great-looking-collapsible-lists-without-uitableview

请参考上面的链接,我想要同样的 swift 。

提前致谢

iphone tableviewcell ios swift

-7
推荐指数
1
解决办法
1万
查看次数