现在我定义一个委托,其中有3个方法:
@protocol A <NSObject>
-(void) a;
-(void) b;
-(void) c;
@end然后在类B中实现委托A的这三个方法,请问,这3个方法的执行顺序是按照什么来的?有没有顺序要求?谢谢

解决方案 »

  1.   

    譬如UITableViewDataSource这个委屈有下面这几个方法:
    // 方法1
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 1;
    }// 方法2
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return 2;
    }// 方法3
    - (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];
        }
        
        // Configure the cell...
        cell.textLabel.text = [_days objectAtIndex:indexPath.row];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        return cell;
    }// 方法4.....上面这几个方法有执行先后顺序吗?
      

  2.   


    numberOfSectionsInTableView方法来返回table中有几个组. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView  
    {  
      return 1;  
    }  numberOfRowsInSection方法来返回每个组里有几行 - (NSInteger)tableView:(UITableView *)tableView  
     numberOfRowsInSection:(NSInteger)section   
    {  
      return [list count];   
    }  最后用cellForRowAtIndexPath
      

  3.   

    LZ,这个是苹果自己设计的一套UITableView的流程。
    是乔布斯手下规定的。
      

  4.   

    如果你是要知道他们的顺序,你可以在 这些方法里面,输入以下代码1:首先在 类中申明一个成员变量   int ncount;2然后在你想知道顺序的方法里做输出测试就可以啦;nslog(@“现在,该方法名 是排行第 ----%i”,ncount);
    ncount++;3打开 调试进入debug,打开consle控制台查看即可。这样就能达到了你的目的。不过意义不大,因为有的时候会重复调用这些方法,比如下拉菜单的时候或者重新进入页面的时候。你可以通过查看 nslog来知道这些方法都运行了没有
      

  5.   

    委托就是用来实现C++中的类实例指针的一个东西,一个类实现了某个协议,那么就能用这个delegate的指针指向这个类,例如
    id<A> myDelegate;myDelegate = b;
    其中,b是类B的实例,B实现了协议A