我遇到了 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);
}