2012-10-31 5 views
18

コンパイル時に別の関数から呼び出す必要があるUITableViewデリゲートメソッドが必要です...私が使用できるデフォルトのUITableViewデリゲートメソッドはありますか?そうでない場合は、既存のものに加えて追加の代理メソッドを追加する方法についてコメントしてください。このメソッドが存在する場合には、事前UITableViewデリゲートメソッド

+0

uは別の関数からのtableViewをリフレッシュする必要がありますか? – AppleDelegate

+0

なぜデリゲートメソッドを作成したいですか?代わりに、関数の完了後にすべてのテーブルデータをリロードすることができます –

+0

問題についての詳細と達成したいことを提供してください。 – Kassem

答えて

39

あなたがいずれかの方法でUITableview委任を設定していることを確認します - NIBまたはprogramatially

からペン先からNIB を使用する: -

enter image description here

プログラムにより: - enter image description here

その後、 : -

-(void)viewWillAppear:(BOOL)animated 
{ 
     tblService.delegate=self; 
     tblService.dataSource=self; 
     [super viewWillAppear:YES]; 
} 

使用以下の代表者:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; //count of section 
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

    return [catagorry count]; //count number of row from counting array hear cataGorry is An Array 
} 



- (UITableViewCell *)tableView:(UITableView *)tableView 
      cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     static NSString *MyIdentifier = @"MyIdentifier"; 

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 

     if (cell == nil) 
     { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
              reuseIdentifier:MyIdentifier] autorelease]; 
     } 

     // Here we use the provided setImageWithURL: method to load the web image 
     // Ensure you use a placeholder image otherwise cells will be initialized with no image 
     [cell.imageView setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"] 
         placeholderImage:[UIImage imageNamed:@"placeholder"]]; 
      cell.textLabel.text = @"My Text"; 
     return cell; 
    } 

Below use for set height of cell

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

     return 80; 

} 

Below use for gatting particular cells data by selecting row this method called

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

     Yourstring=[catagorry objectAtIndex:indexPath.row];  

     //Pushing next view 
     cntrSecondViewController *cntrinnerService = [[cntrSecondViewController alloc] initWithNibName:@"cntrSecondViewController" bundle:nil]; 
     [self.navigationController pushViewController:cntrinnerService animated:YES]; 

} 
+0

http://stackoverflow.com/questions/5831813/delegate-and-datasource-methods-for-uitableview/42105964#42105964 –

4

おかげで、私は知りませんが、あなたがUITableViewデリゲート内の他の方法が必要な場合は、UITableViewDelegateの新しいカテゴリを作成することができます。

関連する問題