相关疑难解决方法(0)

UITableView didSelectRowAtIndexPath:第一次点击时没有调用

我遇到了问题UITableView's didSelectRowAtIndexPath.

我的表是设置的,所以当我选择行时,它会初始化一个新的视图控制器并将其推送.

我第一次点击表中的任何一行时,该方法不会被调用.一旦我选择了另一行,它就会开始正常工作.

我已经通过设置断点来验证这一点didSelectRowAtIndexPath.在向NSLog方法添加时,我看到当我选择最后推送新视图控制器的第二行时,我看到控制台中同时出现两个日志语句.

有什么建议?

cocoa-touch uitableview uikit didselectrowatindexpath

350
推荐指数
6
解决办法
6万
查看次数

didSelectRowAtIndexPath:未被调用

我有一个UITableView作为我的子视图UIScrollVIew,这是我控制的主视图MainViewController.

在MainViewController.h中

@interface MainViewController : UIViewController <UIGestureRecognizerDelegate, UITableViewDelegate, UITableViewDataSource>

// other stuff here...

@property (weak, nonatomic) IBOutlet UITableView *myTableView;
Run Code Online (Sandbox Code Playgroud)

在MainViewController.m中

@synthesize myTableView;

// other stuff here...

- (void)viewDidLoad {
    myTableView.delegate = self;
    myTableView.datasource = self;
}

// other stuff here...

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath {
   [self performSegueWithIdentifier:@"listAttributesSegue" sender:self];
}
Run Code Online (Sandbox Code Playgroud)

我知道didSelectRowAtIndexPath没有被调用,因为我已经在方法本身和它内部的代码行上设置了断点,并且都没有被调用.我也知道数据源工作正常,因为我有其他功能可以在运行时修改单元格,并且它们工作正常.我使用最新的Xcode和iOS 5.0设置作为开发目标.我搜索并搜索了一个答案.有人有主意吗?

编辑: 我找到了答案.我UITapGestureRecognizer有一套myTableView的superView.这超出了选择呼叫.相信任何人都认为可能是它.在我将其标记为正确之前,您的答案已被删除.

编辑2: 很多人一直在评论这个,所以我会分享它.如果您遇到此问题,只需设置myGestureRecognizer.cancelsTouchInViewfalse,一切都应该正常工作.

iphone uitableview didselectrowatindexpath ios

57
推荐指数
6
解决办法
4万
查看次数

编辑时,`UITableView`不会调用didSelectRowAtIndexPath ??

我有一个UITableViewController用户应该能够编辑项目的地方.为了启用编辑我使用这个:

self.navigationItem.rightBarButtonItem = self.editButtonItem;
Run Code Online (Sandbox Code Playgroud)

对于不知道self.editButtonItem来自哪里的每个人,它都是由SDK预定义的.

所以,现在当我按下任何一个项目时,这个方法被称为:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
Run Code Online (Sandbox Code Playgroud)

但是当我点击编辑按钮并且编辑处于活动状态时,似乎没有调用此方法.

知道我错过了什么吗?

这是与编辑相关的其余代码:

// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    return UITableViewCellEditingStyleNone;
}


- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath 
{
    return NO;
}
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助.

MCB

iphone uitableview

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

为什么我不能选择TableView单元格?

这是我的应用程序的流程:

首先,TableView设置为隐藏.屏幕中央有一个UITextField.当用户输入内容并点击Go时,运行以下代码:

self.view.layoutIfNeeded()
UIView.animateWithDuration(0.5, animations: {

    self.textFieldConstraint.constant = -230
    self.tableView.hidden = false
    self.goButton.hidden = true
    self.view.layoutIfNeeded()

}, completion: nil)
Run Code Online (Sandbox Code Playgroud)

此时,将填充tableview.选择行时,我需要操作填充它的数据.

但是,当我点击一个单元格时绝对没有任何反应.

我究竟做错了什么?

我的TableView代码在这里:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell: SearchResultsTableViewCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! SearchResultsTableViewCell

    cell.label.text = searchResultsNames[indexPath.row]

    return cell
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return searchResultsUrls.count

}

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

    print("HELLO")

}
Run Code Online (Sandbox Code Playgroud)

而且,我已正确设置dataSource和委托.

我还想澄清一下tableView是否正确填充和滚动; 当我点击一个单元格时它就不会做任何事情.

更新:

我发现由于某种原因,我可以在按住它们时选择细胞.这不是我想要的,所以有人知道如何解决这个问题吗?

uitableview swift

13
推荐指数
3
解决办法
2万
查看次数

TableViewController使用静态单元格检测行点击

我正在使用一个TableViewController,它有一个包含2个静态单元格的表.它嵌入在视图控制器中.我点击单元格时无法运行didSelectRowAtIndexPath.我已经检查所有常见的犯罪嫌疑人,从这个问题以及一个.当我在带有动态表的viewcontroller中尝试使用表视图时,我能够让它工作得很好.将TableViewController用于不允许使用didSelectRowAtIndexPath的静态单元格是否存在问题?

这是我在TableViewController的自定义类中的内容:

import UIKit

class OptionTableViewController: UITableViewController {


@IBOutlet var optionsTable: UITableView!


let numberOfRows = [7,2]

let cellIdentifier = "OptionCells"

override func viewDidLoad() {
    super.viewDidLoad()

    self.optionsTable.delegate = self
    self.optionsTable.dataSource = self

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

override func numberOfSections(in tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 2
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> …
Run Code Online (Sandbox Code Playgroud)

static uitableview didselectrowatindexpath ios swift3

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