2012-10-31 39 views
18

Tôi cần phương thức ủy quyền UITableView cần được gọi từ một hàm khác tại thời gian biên dịch ... có phương thức ủy quyền mặc định nào là tôi có thể sử dụng không? nếu không, vui lòng nhận xét về cách thêm phương thức đại biểu bổ sung ngoài phương thức hiện có.Phương thức ủy nhiệm của UITableView

Cảm ơn trước

+0

làm u cần phải làm mới tableView từ chức năng khác ??? – AppleDelegate

+0

tại sao bạn muốn tạo phương thức đại biểu? Thay vào đó, bạn có thể tải lại tất cả dữ liệu bảng sau khi hoàn thành chức năng của mình –

+0

vui lòng cung cấp thêm thông tin về sự cố và những gì bạn muốn đạt được. – Kassem

Trả lời

39

Hãy chắc chắn rằng bạn thiết lập UITableview đại biểu trong một trong hai cách - từ NIB hoặc programatially

Sử dụng NIB Từ Nib: -

enter image description here

Programatically: - enter image description here

sau đó : -

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

Sử dụng các đại biểu sau đây:

- (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

Tôi không biết nếu phương pháp này tồn tại nhưng nếu bạn cần các phương pháp khác trong một đại biểu UITableView bạn có thể tạo một loại mới của UITableViewDelegate.

Các vấn đề liên quan