【发布时间】:2010-05-06 18:51:14
【问题描述】:
我已经在我的应用程序上设置了一个分组表,并且推送到新视图工作正常。除了一件事。标题和堆栈布局都很奇怪。这是细分:
- 我的表中有两个部分。
- 当我点击第一部分的第一行时,它会将我带到正确的视图,但新视图的标题是表格第二部分中第一行的名称。
- 反过来,第一节标题中的第二行是第二节标题中的第二行。
如果我点击根视图表第二部分的第二行,导航按钮会转到表的第一部分的第二行。
所以这是我的表格的图表:
表格第 1 节
第 1 行
第 2 行
第 3 行
表第 2 节
A行
B行
C行
所以如果我点击第 3 行,推送视图的标题是 C 行。导航按钮告诉我返回第 3 行,然后最终到达根视图。
这是我推送视图的实现文件:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//CSS
if ([[arryClientSide objectAtIndex:indexPath.row] isEqual:@"CSS"])
{
CSSViewController *css = [[CSSViewController alloc] initWithNibName:@"CSSViewController" bundle:nil];
[css setTitle:@"CSS"];
[self.navigationController pushViewController:css animated:YES];
}
//HTML
if ([[arryClientSide objectAtIndex:indexPath.row] isEqual:@"HTML"])
{
HTMLViewController *html = [[HTMLViewController alloc] initWithNibName:@"HTMLViewController" bundle:nil];
[html setTitle:@"HTML"];
[self.navigationController pushViewController:html animated:YES];
}
//JS
if ([[arryClientSide objectAtIndex:indexPath.row] isEqual:@"JavaScript"])
{
JSViewController *js = [[JSViewController alloc] initWithNibName:@"JSViewController" bundle:nil];
[js setTitle:@"JavaScript"];
[self.navigationController pushViewController:js animated:YES];
}
//PHP
if ([[arryServerSide objectAtIndex:indexPath.row] isEqual:@"PHP"])
{
PHPViewController *php = [[PHPViewController alloc] initWithNibName:@"PHPViewController" bundle:nil];
[php setTitle:@"PHP"];
[self.navigationController pushViewController:php animated:YES];
}
//SQL
if ([[arryServerSide objectAtIndex:indexPath.row] isEqual:@"SQL"])
{
SQLViewController *sql = [[SQLViewController alloc] initWithNibName:@"SQLViewController" bundle:nil];
[sql setTitle:@"SQL"];
[self.navigationController pushViewController:sql animated:YES];
}
& 提供表格数据的数组:
- (void)viewDidLoad {
[super viewDidLoad];
arryClientSide = [[NSArray alloc] initWithObjects:@"CSS",@"HTML",@"JavaScript",nil];
arryServerSide = [[NSArray alloc] initWithObjects:@"Objective-C", @"PHP",@"SQL",nil];
// arryResources = [[NSArray alloc] initWithObjects:@"HTML Colour Codes", @"Useful Resources", @"About",nil];
self.title = @"Select a Language";
[super viewDidLoad];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
我们将非常感谢提供任何帮助。
杰克
【问题讨论】:
-
神圣的内存泄漏,蝙蝠侠! (每次你
alloc/init一个新的viewController,你应该在推送后release它)
标签: iphone objective-c uitableview uinavigationcontroller grouped-table