【问题标题】:what is the difference between didselectrowindexpath and willselectrowindexpath in iphone?iphone中的didselectrowatindexpath和willselectrowindexpath有什么区别?
【发布时间】:2012-06-11 03:54:30
【问题描述】:

解释UITableView委托方法的区别:

didDeselectRowAtIndexPath:

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath  

willSelectRowAtIndexPath

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath 

【问题讨论】:

  • willSelectRowAtIndexPath 在行被选中之前被调用,在行被选中后被调用 didDeselectRowAtIndexPath。
  • 你能用示例代码解释一下吗
  • @Prim.Muthu: 只需在.m 文件中写入这两个方法并在它们上放置断点你就会明白..

标签: iphone ios5 uitableview didselectrowatindexpath


【解决方案1】:

写的代码

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath(NSIndexPath*)indexPath 

方法在选中行后运行,代码写在里面

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath(NSIndexPath*)indexPath 

在所选行之前运行。

它们与

相同
- (void)viewDidAppear:(BOOL)animated and - (void)viewWillAppear:(BOOL)animated

如果您现在有任何困惑,请告诉我。

【讨论】:

    【解决方案2】:

    willSelectRowAtIndexPath 消息在用户从触摸特定行抬起手指之后、didSelectRowAtIndexPath 之前发送给UITableView 代表。

    willSelectRowAtIndexPath 允许您通过返回indexPath 来确认可以选择特定行,或者通过提供备用indexPath 来选择不同的行。

    祝你好运

    T

    【讨论】:

      猜你喜欢
      • 2010-10-09
      • 2010-12-29
      • 1970-01-01
      • 2012-09-03
      • 1970-01-01
      • 2010-10-02
      • 2011-12-12
      • 2010-09-16
      • 2012-03-14
      相关资源
      最近更新 更多