0

プログラムで生成された を使用しUITableViewてポップアップし、UITextField. ユーザーがタッチするUITextFieldと、有効な値の TableView がポップアップ表示されます。UITableViewセクションと検索バーがあります。私が作成した別の非常によく似たアプリからコードを取得しましたが、正常に動作します。

UITextFieldをタッチすると、( ) で実行が開始されますがUITableViewCatagoryTableViewController.minit メソッドのみが呼び出され、呼び出し元のクラスに制御が戻ります ( ViewController.m)。UITextField のキー ポップアップをオーバーライドしました。

用の XIB はありますが、用はありViewControllerませんCatagoryTableViewController。UITextField Touch Down がcatagoryFieldPressedメソッドにマップされます。

ちなみに、SFCLog は次のように定義されています。

define SFCLog(FORMAT, ...) fprintf(stderr,"%s [line %d] %s\n",__PRETTY_FUNCTION__, __LINE__,[[NSString stringWithFormat:FORMAT, ##__VA_ARGS__]  UTF8String])

のすべてのメソッドの先頭に SFCLog ログ (NSLog のバリエーション) を配置しましたがCatagoryTableViewController、init だけが呼び出されます。私が欠けているものについてのアイデアはありますか?

FromViewController.h (呼び出しクラス ヘッダー)

@interface ViewController : UIViewController <UITextFieldDelegate>
{
    Word *currentWord;
    NSMutableArray *words;
    int wordsIndex;
    int viewState;
    int correctCounter;
    int incorrectCounter;
}

FromViewController.m (呼び出しクラス)

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    SFCLog(@"");
    return NO;  // Hide both keyboard and blinking cursor.
}

- (IBAction)catagoryFieldPressed:(id)sender
{
    SFCLog(@"Catagory button");
    CatagoryTableViewController *childView = [[CatagoryTableViewController alloc] init];
    childView.parentView = self;
    [self.navigationController pushViewController:childView animated:YES];
    SFCLog(@"Returned from Catagory button");
}

CatagoryTableViewController.h

@class ViewController;

@interface CatagoryTableViewController : UITableViewController <UISearchBarDelegate> 
{
    NSMutableDictionary *catagoryDictionary;
    NSArray *filteredArray;
    UISearchBar *searchBar;
    UISearchDisplayController *searchController;
    NSMutableArray *sectionArray;
}

@property (nonatomic, weak) ViewController *parentView;

CatagoryTableViewController.mこれよりもはるかに多くのコードがありますが、これらのメソッドが起動するはずです。

@implementation CatagoryTableViewController
@synthesize parentView;


- (id) init
{
    SFCLog(@"");
    if ((self = [super init]))
    {
        SFCLog(@"in here");        
    }
    SFCLog(@"");
    return self;
}


- (void)viewDidLoad
{
    SFCLog(@"");
    [super viewDidLoad];
}

-(void)loadView
{
    SFCLog(@"load view");
    [super loadView];
    self.navigationItem.hidesBackButton = TRUE;

    // Load the catagory dictionary from the database
    WordService *wordService = [[WordService alloc] init];
    NSMutableArray *rawCatagories = [wordService getCatagories];
    catagoryDictionary = [NSMutableDictionary dictionary];
    for (WordCatagory *wordCatagory in rawCatagories) {
        [catagoryDictionary setObject:wordCatagory forKey:wordCatagory.wordCatagory];
    }

    // Section Array
    sectionArray = [NSMutableArray array];
    for (int i = 0; i < 26; i++)
        [sectionArray addObject:[self itemsInSection:i]];
    SFCLog(@"sectionArray: %@",sectionArray);


    // Create a search bar
    searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
    searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
    searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
    searchBar.keyboardType = UIKeyboardTypeAlphabet;
    self.tableView.tableHeaderView = searchBar;

    // Create the search display controller
    searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
    searchController.searchResultsDataSource = self;
    searchController.searchResultsDelegate = self;   
}

コンソール出力のデバッグ

 [ViewController catagoryFieldPressed:] [line 223] Catagory button
 [CatagoryTableViewController init] [line 18] 
 [CatagoryTableViewController init] [line 21] in here
 [CatagoryTableViewController init] [line 23] 
 [ViewController catagoryFieldPressed:] [line 227] Returned from Catagory button
 [ViewController textFieldShouldBeginEditing:] [line 33] 

Phillip Mills の投稿に従って NSLog を追加した後、デバッグ コンソールの出力を編集しました。

-[ViewController catagoryFieldPressed:] [line 223] Catagory button
-[CatagoryTableViewController init] [line 18] 
-[CatagoryTableViewController init] [line 21] in here
-[CatagoryTableViewController init] [line 23] 
-[CatagoryTableViewController loadView] [line 171] load view
2012-06-04 18:52:57.930 Fluent[1835:f803] Opened database
2012-06-04 18:52:57.930 Fluent[1835:f803] Path: /Users/sean/Library/Application Support/iPhone Simulator/5.1/Applications/8B93174F-8836-4533-BCFF-F98AC2F34F26/Documents/fluent_tr.sqlite
-[WordService getCatagories] [line 114] 
-[CatagoryTableViewController itemsInSection:] [line 46] 
(edited repeating NSLogs to shorten)
-[CatagoryTableViewController firstLetter:] [line 39] 
-[CatagoryTableViewController numberOfSectionsInTableView:] [line 99] 
-[CatagoryTableViewController tableView:titleForHeaderInSection:] [line 86] 
-[CatagoryTableViewController firstLetter:] [line 39] 
-[CatagoryTableViewController tableView:numberOfRowsInSection:] [line 108] 
2012-06-04 18:52:57.937 Fluent[1835:f803] Rows per section count: 1
-[CatagoryTableViewController viewDidLoad] [line 31] 
2012-06-04 18:52:57.938 Fluent[1835:f803] Controller: <CatagoryTableViewController: 0x884c880>, View: <UITableView: 0xbb90a00; frame = (0 20; 320 460); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x884ce20>; contentOffset: {0, 0}>
-[ViewController catagoryFieldPressed:] [line 228] Returned from Catagory button
-[ViewController textFieldShouldBeginEditing:] [line 33] 

AppDelegate.m の前

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    UIViewController *viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    UIViewController *numberTestViewController = [[ViewController alloc] initWithNibName:@"NumberTestViewController" bundle:nil];

    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
    nav.tabBarItem.title = @"Words";
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController,numberTestViewController, nil];
    self.tabBarController.delegate = self;
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

AppDelegate.m の後

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    ViewController *viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    NumberTestViewController *numberTestViewController = [[NumberTestViewController alloc] initWithNibName:@"NumberTestViewController" bundle:nil];

    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav,numberTestViewController, nil];
    self.tabBarController.delegate = self;
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}
4

1 に答える 1

0

Phillip Mills の助けを借りて、問題を発見しました。UITableView を呼び出していたビュー コントローラーが、ナビゲーション スタックに正しく追加されませんでした。インスタンス化されてからUINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];、ナビゲーション コントローラーに追加されましたが、ナビゲーション コントローラー自体が正しくタブバー コントローラーに追加されませんでした。

上記の AppDelegate.m の前後のバージョンを参照してください。

助けてくれてありがとうフィリップ。

于 2012-06-04T20:02:43.677 に答える