私はメインメニューを持つビューベースのアプリケーションを持っています。メインメニューでは、SQLiteデータベース(BrowseView)から読み込まれたテーブルを表示するオプションを選択できます。それはすべて正常に動作していますが、テーブルからは詳細なビューを表示するデータの行を選択できるようにしたいので、詳細ビューを表示することはできません。何も起こりません。UINavigation Controllerをビューベースのアプリケーション内でテーブルビューに接続
UINavigationコントローラに詳細なビューを接続していないのが問題だと思いますが、私が考えることができるすべてを試したので、これを行う方法はわかりません(おそらく新しいプログラミングです)。
これに関する助言は、大いに評価されます。ここに私のコードです。
appDelegate.hで@class ClubFindViewController;
@interface ClubFindAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
ClubFindViewController *viewController;
UINavigationController *navigationController;
NSMutableArray *clubArray;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet ClubFindViewController *viewController;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) NSMutableArray *clubArray;
-(void) copyDatadaseIfNeeded;
-(NSString *) getDBPath;
@end
AppDelegate.m
@implementation ClubFindAppDelegate
@synthesize window;
@synthesize viewController;
@synthesize navigationController;
@synthesize clubArray;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self copyDatadaseIfNeeded];
NSMutableArray *tempArray = [[NSMutableArray alloc]init];
self.clubArray = tempArray;
[tempArray release];
[Clubs getInitialDataToDisplay:[self getDBPath]];
self.window.rootViewController = self.navigationController;
[self.window addSubview:navigationController.view];
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
DetailView.h
@class Clubs;
@interface DetailViewController : UITableViewController {
IBOutlet UITableView *tableView;
Clubs *clubObj;
}
@property (nonatomic, retain) Clubs *clubObj;
@property (nonatomic, retain) IBOutlet UITableView *tableView;
@end
DetailView.m
#import "DetailViewController.h"
#import "Clubs.h"
#import "BrowseViewController.h"
@implementation DetailViewController
@synthesize clubObj;
@synthesize tableView;
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.title = clubObj.clubName;
[self.tableView reloadData];
}
-(NSString *)tableView:(UITableView *)tblView titleForHeaderInSection: (NSInteger)section {
NSString *sectionName = nil;
switch (section) {
case 0:
sectionName = [NSString stringWithFormat:@"Club"];
break;
case 1:
sectionName = [NSString stringWithFormat:@"Address"];
break;
}
return sectionName;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return 1;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tblView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
switch (indexPath.section) {
case 0:
cell.textLabel.text = clubObj.clubName;
break;
case 1:
cell.textLabel.text = clubObj.ClubAddress;
break;
}
return cell;
}
コードを更新しました。
あなたのレスポンスのためにCyprianに感謝していますが、それでもうまくいきませんでした。@ Cyrpian – Wayne
時には小さな事が間に合わないことがありますが、私があなたに与えたアプローチはうまくいくはずです。 Plsはあなたのコードを更新します。 AppDelegateクラスと.hと.mの詳細ファイルを見てみましょう。もう一つ、MainWindow.xibにUINavigationViewControllerを挿入しましたか?テンプレート「ナビゲーションベースのアプリケーション」から新しいプロジェクトを作成することをお勧めします。これはUINavigationViewControllerをセットアップします。 – Cyprian
要求通りにコードを更新しました。いいえ、MainWindow.xibにUINaviagationViewControllerを挿入していません(どうすればいいですか)。私はorginalyが "Navigation based templete"を使用してプログラムを作成しましたが、私はメインメニュービュー(このビューを追加する前にDetailViewの作業)を追加してビューベースのアプリケーションに変更することをお勧めしました@ Cyprian – Wayne