1

我已经设置了一个表视图控制器并连接了一个子视图,所以当我点击新的子视图出现的行时。我一步一步跟踪了一些教程,但由于某种原因,当我单击行时(即使正在选择行),也没有出现。从桌面视图控制器推视图控制器不起作用

这是我的主视图控制器:

@interface TableViewsViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> { 

IBOutlet UITableView *tblSimpleTable; 
IBOutlet UINavigationBar *navBar; 
NSArray *arryData; 
NSMutableArray *listOfItems; 
} 

@property (nonatomic, retain) IBOutlet UITableView *tblSimpleTable; 
@property (nonatomic, retain) IBOutlet UINavigationBar *navBar; 
@property (nonatomic, retain) NSArray *arryData; 
@property (nonatomic, retain) NSMutableArray *listOfItems; 

的.m(相关部分)

// 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: UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; 
} 

NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section]; 
NSArray *array = [dictionary objectForKey:@"Computers"]; 
NSString *cellValue = [array objectAtIndex:indexPath.row]; 
cell.textLabel.text = cellValue; 

return cell; 

} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *) indexPath 
{ 

NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section]; 
NSArray *array = [dictionary objectForKey:@"Computers"]; 
NSString *selectedCountry = [array objectAtIndex:indexPath.row]; 

//Initialize the detail view controller and display it. 
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]]; 
dvController.selectedComputer = selectedCountry; 
[self.navigationController pushViewController:dvController animated:YES]; 
dvController = nil; 

} 

而子视图控制器:

.H

@interface DetailViewController : UIViewController { 

IBOutlet UILabel *lblText; 
NSString *selectedComputer; 


} 

@property (nonatomic, retain) IBOutlet UILabel *lblText; 
@property (nonatomic, retain) NSString *selectedComputer; 

@end 

。 m

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view from its nib. 

//Display the selected country. 
lblText.text = selectedComputer; 

//Set the title of the navigation bar 
self.navigationItem.title = @"Selected Computer"; 

} 

我很确定IB的一切都很好连接。

感谢您的帮助!

+0

导航栏在选择行之前是否出现在tableView上方?代码看起来是正确的,所以我会仔细检查连接并确保navigationController设置正确。 – PengOne

+0

记录'dvController'并查看它是否为'nil'。 – 2011-07-14 21:11:34

+0

dvController不是零 – TommyG

回答

2

是导航控制器中的表格视图。你可以把一个断点放在

[self.navigationController pushViewController:dvController animated:YES]; 

并在self.navigationController属性上获得战利品。如果它是零,你将无法将任何东西推到它上面,但它不会给你一个错误,因为发送消息到零将仅在大多数情况下返回零。

+0

是的,它是零....我意识到我没有定义它...奇怪。我从教程中逐字逐句地接受它。 – TommyG

+0

很多时候,它最让你困扰的小事情。 :) –

+0

我看到,在许多地方,他们在AppDelegate中进行了一些定义 - 是吗?虽然我仍然是初学者,但我尽量不要碰这个东西....谢谢! – TommyG

1

可能是一个小看起来。如果您从模板创建DetailedViewController并且检查为它创建一个nib文件,则nib文件应该与.h和.m文件具有相同的名称。因此请检查您的笔尖班的名字。它可能应该是:

DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]; 

P.S.使用self.这里:

self.dvController = nil; 

否则你会泄漏。

+0

有趣的是,initWithNibName被设置为另一个名字实际上(就像我说的,我从教程中复制了这个,但是改变了文件名),但是一旦我修复了它,它仍然不起作用。 – TommyG

+0

也重新泄漏 - 我们仍然需要这与ARC? – TommyG