0

タブ バー アプリケーションを作成し、デフォルトの FirstView と SecondView を削除し、次の 2 つの ViewController を追加しました。

  1. JustAnotherView (これは、内部に UIView を持つ単なる UIViewController です)
  2. MyListOfItems (これは、内部に TableView を持つ UIViewController です)

ユーザーが TableView セルの 1 つに触れたときに呼び出されることになっている UIView を内部に持つ ListOfItemsDetailViewController と呼ばれる 3 番目の ViewController があります。

アプリケーションは問題なくコンパイルされます。両方のタブ バー ボタンをタッチすると、正しいビューが表示されます。

問題: TableView セルをクリックすると、詳細ビ​​ューに切り替えるコードが (クラッシュやエラーなしで) 実行されますが、ビューは表示されません。

これは、クラッシュすることなく pushViewController を通過したことを示す NSLog を含むアプリケーションとデバッガーのスクリーンショットです。

http://clip2net.com/clip/m52549/thumb640/1281588813-9c0ba-161kb.jpg

これがコードです。

MyListOfItemsViewController.h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "ListOfItemsDetailViewController.h";

@interface MyListOfItemsViewController : UIViewController {
    ListOfItemsDetailViewController *listOfItemsDetailViewController;
}

@property (nonatomic, retain) ListOfItemsDetailViewController *listOfItemsDetailViewController;


@end

MyListOfItemsViewController.m ファイルは次のとおりです。

#import "MyListOfItemsViewController.h"
@implementation MyListOfItemsViewController
@synthesize listOfItemsDetailViewController;

#pragma mark -
#pragma mark View lifecycle

- (void)viewDidLoad {
    [super viewDidLoad];

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    self.title = @"My List Of Items";
    NSLog(@"My List Of Items Did Load");
}

#pragma mark -
#pragma mark Table view data source
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 5;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    NSString *cellMessage;

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    cellMessage = [NSString stringWithFormat:@"indexPath: %d",indexPath.row];       
    cell.textLabel.text = cellMessage;
    return cell;
}

#pragma mark -
#pragma mark Table view delegate

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

    ListOfItemsDetailViewController *vcListOfItemsDetail = [[ListOfItemsDetailViewController alloc] 
                                    initWithNibName:@"ListOfItemsDetail" bundle:[NSBundle mainBundle]];
    self.listOfItemsDetailViewController = vcListOfItemsDetail;
    [vcListOfItemsDetail release];
    [self.navigationController pushViewController:self.listOfItemsDetailViewController animated:YES];

    NSLog(@"Did Execute didSelectRowAtIndexPath WITHOUT Crashing or Error.");

}

#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
    NSLog(@"My List Of Items View Did Unload");
}


- (void)dealloc {
    [super dealloc];
}



@end

助けてください。それは非常に高く評価されます!!!

基本的なナビゲーションを iOS プラットフォームに取り込もうとして、私は頭がおかしくなりました。

また、素人の質問で申し訳ありませんが、ほとんどの人はすでにこれを行う方法を理解していると思います。

前もって感謝します。ヤオスン

4

2 に答える 2

1

2 番目のタブのビューコントローラーを tableviewcontroller にする代わりに、UINavigationController にして、navcontroller の RootViewController を「MyListOfItems」として設定します。これを行うと、viewcontroller の navigationController プロパティにアクセスできるようになり、push と pop を使用できるようになります。

または、これを行いたくない場合は、プログラムでビュー間をアニメーション化するしかありません (つまり、1 つのビューを削除して別のビューを追加するか、現在のビューの上に別のビューを追加します)。

于 2010-08-12T06:42:36.677 に答える
0

で、tableView:didSelectRowAtIndexPath:navigationController を参照していますがself.navigationController、存在しない可能性があります。UINavigationController を tabView の 1 つのビュー コントローラーとして使用する必要があり、その navigationController の rootViewController は MyListOfItemsViewController である必要があります。

詳細ビューをプッシュするには UINavigationController が必要であり、self.navigationController は、以前に作成されて階層に挿入されたものを取得する唯一の方法であることに注意してください。

于 2010-08-12T05:32:10.783 に答える