0
嘿傢伙, 我有一個正確的表視圖排序,但我有一個問題,當我是我的表視圖上的每個數據打開同一個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是我的執行文件,我也添加了對筆尖文件,
所以希望有人能幫助我如何讓每個數據打開自己的看法,我不會介意我是否必須做出一個IB文件對每個和我所有的數據在我的表視圖,
感謝
嘿感謝,我就要現在嘗試一下,但我想知道什麼是nibName? – PatrickGamboa 2011-04-05 16:32:36
nibName是用於UIViewController初始化'initWithNibName'的名稱。這些是界面生成器xib文件。看看蘋果的[資源編程指南](http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/LoadingResources/CocoaNibs/CocoaNibs.html#//apple_ref/doc/uid/10000051i- CH4-SW8) – 2011-04-05 17:05:13
嘿我試圖把這些部分放在一起時遇到了麻煩,我正在查看資源編程指南,然後我實現了您的代碼,但它立刻崩潰了,我不確定您的代碼是否正常工作。如果沒關係,我想指出一些我不明白的東西。 indexPath.section,我不認爲我需要每個類別的1個nib文件,在我的.plist中我有21個數據,我想說的是,當我在我的plist中有21個數據時,我想要21個nib文件,每個筆尖打開他們自己的數據,因爲我的.plist中的每個數據將具有與其他人不同的說明(對於我的英語不好)對於 – PatrickGamboa 2011-04-06 15:03:10