【发布时间】:2012-02-24 05:03:42
【问题描述】:
iOS 5 的 UITableView 的 didSelectRowAtIndexPath 存在问题,这在 ios 4 中是正确的。
第一次点击表格中的任何行时,不会调用该方法。一旦我选择了另一行,它就会调用 didSelectRowAtIndexPath,但会传递最后一个 indexPath。
tableView.delegate我已经设置好了,在ios4下可以正常运行。
MainView.xib
UITabBarController
--UINavigationController
--**UITableViewController**
有什么建议吗?
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.delegate = self;
self.tableView.dataSource = self;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [[NSString alloc]initWithFormat:@"%d",indexPath.row];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%d",indexPath.row);
}
【问题讨论】:
-
你能发布代码吗?你确定你没有实现 didDeselectRowAtIndexPath 吗?
-
我没有实现取消选择。谢谢。
-
@AnnaKarenina - 今天早上我遇到了这个问题,Anna Karenina 再次拯救了我的皮肤 - 谢谢 :)
-
这个问题解决了吗?你能回答(你自己的)这个问题,所以我们可以关闭它!?
标签: uitableview ios5 didselectrowatindexpath