【发布时间】:2013-11-16 15:24:35
【问题描述】:
我在采用UITableViewDelegate 和UITableViewDataSource 协议的UIViewController 中有一个UITableView。 numberOfRowsInSection 和 cellForRowAtIndexPath 已实现。
情节提要中有数据源和委托的出口。为 TableView 选择了单选。触摸时显示选择被选中。
我在模拟器上运行项目,触摸表格单元格,得到了didHighlightRowAtIndexPath 的调用,但从未调用过didSelectRowAtIndexPath 或willSelectRowAtIndexPath。
我忘记了什么?什么会以这种方式影响 TableView?
附:我知道,有很多这样的问题,但我花了几个小时谷歌搜索和阅读 stackoverflow,但仍然没有解决我的问题。
TestViewController.h:
@interface TestViewController : ViewController <UITableViewDelegate, UITableViewDataSource>
@end
TestViewController.m:
@interface TestViewController ()
@property (strong) IBOutlet UITableView *tableView;
@end
@implementation TestViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"selected");
}
- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"highlighted");
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"FilterCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.textLabel.text = @"some text";
return cell;
}
@end
【问题讨论】:
-
您不认为添加代码会有帮助吗?还是您希望我们具备读心术的能力?
-
@vikingosegundo 我会添加它,但没有什么特别的。我什至把我的班级改成了一个简单的班级,只是为了测试
-
@Serhii Yakovenko,它是从 STableViewController 继承的 ViewController(用于“加载更多”实现)。名字不好,我知道
标签: ios objective-c uitableview selection