テーブルビューコントローラをセットアップし、サブビューを接続しました。そのため、新しいサブビューが表示されます。私はいくつかのチュートリアルをステップバイステップで実行しましたが、何らかの理由で行をクリックすると何も表示されません(行は選択されています)。テーブルビューコントローラからビューコントローラを押しても動作しません
@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に接続されていることを確信しています。
ありがとうございました!
行を選択する前にnavigationBarがtableViewの上に表示されますか?コードが正しいように見えるので、接続を2回確認し、navigationControllerが正しく設定されていることを確認します。 – PengOne
'dvController'を記録し、それが' nil'であるかどうかを確認します。 –
dvControllerはnilではありません – TommyG