2011-04-05 5 views
0

안녕하세요, 테이블 뷰가 제대로 정렬되었지만 문제가 있습니다. 테이블 뷰의 각 데이터가 하나의 동일한 nib 파일을 열 때 이 코드를 사용하여 :각 데이터는 테이블 뷰에서 고유 한 nib 파일을 엽니 다.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
     // Return the number of sections. 
     return 4; 
} 

// Category 
- (NSString *)tableView:(UITableView *)tableView 
titleForHeaderInSection:(NSInteger)section { 
     if (section == 0) return @"In-Site SEO"; 
     if (section == 1) return @"Inside Analysis"; 
     if (section == 2) return @"Ranks N Stuff"; 
     if (section == 3) return @"Server Info"; 
     return @"Other"; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
     // Return the number of rows in the section. 
     if (section == 0) return 7; 
     if (section == 1) return 3; 
     if (section == 2) return 6; 
     if (section == 3) return 5; 
     return 0; 
} 

// Customize the appearance of table view cells. 
- (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... 
     NSUInteger row = [indexPath row]; 
     if (indexPath.section == 1) row += 7; 
     if (indexPath.section == 2) row += 10; 
     if (indexPath.section == 3) row += 16; 
     if (indexPath.section == 4) row += 21; 
     cell.textLabel.text = [glossaryArray objectAtIndex:row]; 

     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

     return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
     NSInteger row = [indexPath row]; 
     if (self.glossaryDetailViewController == nil) { 
       GlossaryDetailViewController *aGlossaryDetail = [[GlossaryDetailViewController alloc] initWithNibName:@"GlossaryDetailViewController" bundle:nil]; 
       self.glossaryDetailViewController = aGlossaryDetail; 
       [aGlossaryDetail release]; 
     } 
     glossaryDetailViewController.title = [NSString stringWithFormat:@"%@", [glossaryArray objectAtIndex:row]]; 

     NewReferencemoi_caAppDelegate *delegate = (NewReferencemoi_caAppDelegate *)[[UIApplication sharedApplication] delegate]; 
     [delegate.glossaryNavController pushViewController:glossaryDetailViewController animated:YES]; 
} 
  • GlossaryDetailViewController 내 구현 파일이며, 또한 내가 그것에 대해 nib 파일을 추가,

그래서 잘하면 사람이 어떻게 각각의 데이터가 자신의보기를 열 것으로 나를 도울 수를, 내가해야 할 일이 있다면별로 신경 쓰지 않아. 내 테이블 뷰의 각 내 모든 데이터에 대한 IB 파일,

감사

답변

0

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
     NSInteger row = [indexPath row]; 
     NSString *nibName; 

     if (indexPath.section == 1) nibName = @"firstNib"; 
     if (indexPath.section == 2) nibName = @"secondNib"; 
     if (indexPath.section == 3) nibName = @"thirdNib"; 
     if (indexPath.section == 4) nibName = @"fourthNib"; 

     GlossaryDetailViewController *aGlossaryDetail = [[GlossaryDetailViewController alloc] initWithNibName:nibName bundle:nil]; 
     self.glossaryDetailViewController = aGlossaryDetail; 
     [aGlossaryDetail release]; 

     glossaryDetailViewController.title = [NSString stringWithFormat:@"%@", [glossaryArray objectAtIndex:row]]; 

     NewReferencemoi_caAppDelegate *delegate = (NewReferencemoi_caAppDelegate *)[[UIApplication sharedApplication] delegate]; 
     [delegate.glossaryNavController pushViewController:glossaryDetailViewController animated:YES]; 
} 
+0

감사 이봐, 임 지금 그것을 밖으로 시도하려고 시도 할 수 있습니다 코드 스타일에 넣어,하지만 난하려면 nibName이 무엇인지 알고 싶습니까? – PatrickGamboa

+0

nibName은 UIViewController의 initiji initWithNibName에 사용하는 이름입니다. 인터페이스 빌더 xib 파일입니다. Apple의 [Resource Programming Guide] (http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/LoadingResources/CocoaNibs/CocoaNibs.html#//apple_ref/doc/uid/10000051i- CH4-SW8) –

+0

안녕하세요. 조각을 모으는 데 문제가 있습니다. 리소스 프로그래밍 가이드를 살펴본 후 코드를 구현했지만 바로 충돌했습니다. 코드가 작동하는지 확실하지 않습니다. 괜찮 으면 나는 이해하지 못하는 것을 지적하고 싶다. indexPath.section, 나는 각 카테고리에 대해 1 개의 nib 파일을 원한다고 생각하지 않는다. 21 개의 데이터를 갖고 있는데, 21 개의 데이터를 가질 때 21 개가 필요하다. nib 파일, 각각의 펜촉은 자신의 데이터를 열 때마다 .plist의 각 데이터가 다른 것보다 다른 desciption을 갖습니다. (내 나쁜 영어로 유감입니다.) – PatrickGamboa

관련 문제