2014-03-26 2 views
0

내 스토리 보드에 viewcontroller를 설정하고이 뷰 컨트롤러 내에 tableView를 삽입했습니다. [self.tableView reloadData]하고 싶습니다.특정 테이블을 식별 한 다음로드/다시로드

내 viewController.m의 모습입니다. 내 tableView는 sharedView라는 IBOutlet이므로 메서드의 이름이지만 configureView를 호출 할 때 viewDidLoad와 같은 잘못된 작업을하고 있습니다. 그 다음에는 [self.sharedView reloadData]; 데이터가 테이블 내부에 표시되지 않습니다.

#import "DetailViewController.h" 
    #import "sharedUsersTable.h" 

    @interface DetailViewController() 
    - (void)configureView; 
    @end 

    @implementation DetailViewController 

    #pragma mark - Managing the detail item 

    - (void)setDetailItem:(id)newDetailItem 
    { 
     if (_detailItem != newDetailItem) { 
      _detailItem = newDetailItem; 

      // Update the view. 
      [self configureView]; 
     } 
    } 

    - (void)configureView 
    { 
     // Update the user interface for the detail item. 

     if (self.detailItem) { 
      self.detailDescriptionLabel.text = [[self.detailItem objectForKey:@"lock_name"] description]; 

      activeUsers = [self.detailItem objectForKey:@"active_shared_users"]; 
      [self.sharedView reloadData]; 

      //NSLog(@"Info: %@", activeUsers); 
     } 
    } 


    - (void)viewDidLoad 
    { 
     [super viewDidLoad]; 
     // Do any additional setup after loading the view, typically from a nib. 
     [self configureView]; 
    } 

    - (void)didReceiveMemoryWarning 
    { 
     [super didReceiveMemoryWarning]; 
     // Dispose of any resources that can be recreated. 
    } 

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    { 
     return 1; 
    } 

    -(NSString *)sharedView:(UITableView *)sharedView titleForHeaderInSection:(NSInteger)section { 
     return @"Shared with"; 
    } 

    - (NSInteger)sharedView:(UITableView *)sharedView numberOfRowsInSection:(NSInteger)section 
    { 
     return activeUsers.count; 
    } 

    - (sharedUsersTable *)sharedView:(UITableView *)sharedView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     static NSString *CellIdentifier = @"sharedUser"; 


     sharedUsersTable *cell = [sharedView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[sharedUsersTable alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
     } 

     NSDictionary *key; 
     NSString *name; 
     NSString *email; 
    // NSString *permission; 

     key = [activeUsers objectAtIndex:indexPath.row]; 
     name = [key objectForKey:@"shared_user_name"]; 
     email = [key objectForKey:@"email"]; 

     NSLog(@"Info: %@", name); 

     cell.textLabel.text = [NSString stringWithFormat:@"%@", name]; 
     cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", email]; 

     return cell; 
    } 

    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     // Return NO if you do not want the specified item to be editable. 
     return YES; 
    } 


    @end 
+0

논문 jQuery과 대신 "있는 tableView"의 "shareView"로 시작하는 대의원 방법으로 무엇입니까? – Larme

+0

네, 그걸 섞어 놓은 것 같아요. 정확히 내가 뭘 잘못 했니? – Angad

답변

2

당신이 당신의 VC가 구현되는 프로토콜에 대한 정보를 추가해야합니다 또한 데이터 소스를 설정하고 스토리 보드에 직접 위임 할 수 있습니다

- (void)configureView 
    { 
     // Update the user interface for the detail item. 

     if (self.detailItem) { 
      self.detailDescriptionLabel.text = [[self.detailItem objectForKey:@"lock_name"] description]; 

      activeUsers = [self.detailItem objectForKey:@"active_shared_users"]; 
      /* I assume that Your table view is self.sharedView though You should change the name and I assume that it is connected to VC */ 
      self.sharedView.dataSource = self; 
      self.sharedView.delegate = self; 

      [self.sharedView reloadData]; 

      //NSLog(@"Info: %@", activeUsers); 
     } 
    } 

- 나는 당신이 생각 ctrl + 테이블보기에서 vc로 드래그하십시오. 죄송합니다. 이것이 올바르지 않은 경우 - IB 전용 코드를 오랫동안 사용하지 않습니다.

그리고 더 읽을 거리 : https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDataSource_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UITableViewDataSource 메소드 이름을 프로토콜과 완전히 동일하게 변경하십시오. 작동하지 않으면 변경되지 않습니다. 더 나은 undesstanding 데이터 소스 및 대의원

시도 : https://developer.apple.com/library/ios/documentation/userexperience/conceptual/tableview_iphone/CreateConfigureTableView/CreateConfigureTableView.html

+0

감사! 이제 작동합니다. – Angad

0

당신은 UITableViewController가 아니라 UIViewController를 사용한다고 언급했습니다. UIViewController를 사용하는 경우 UITableViewDelegate 및 UITableViewDataSourceDelegate를 구현해야합니다. 코드 또는 인터페이스 빌더 또는 스토리 보드를 사용하여 위임자를 연결해야합니다. 다음

@interface DetailViewController() <UITableViewDataSource, UITableViewDelegate> 
- (void)configureView; 
@end 

과 :

+0

정확히 어떻게합니까? – Angad

관련 문제