我已经设置了一个表视图控制器并连接了一个子视图,所以当我点击新的子视图出现的行时。我一步一步跟踪了一些教程,但由于某种原因,当我单击行时(即使正在选择行),也没有出现。从桌面视图控制器推视图控制器不起作用
这是我的主视图控制器:
@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的一切都很好连接。
感谢您的帮助!
导航栏在选择行之前是否出现在tableView上方?代码看起来是正确的,所以我会仔细检查连接并确保navigationController设置正确。 – PengOne
记录'dvController'并查看它是否为'nil'。 – 2011-07-14 21:11:34
dvController不是零 – TommyG