我正在构建一个应用程序,它使用以编程方式生成的UITableView
来弹出并填充UITextField
。当用户触摸UITextField
时,应弹出有效值的TableView。 UITableView
包含部分和搜索栏。我从我写的另一个非常类似的应用程序中获取了代码,它可以正常工作。
当触摸UITextField
时,执行从UITableView
(CatagoryTableViewController.m
)开始,但只调用init方法,然后控制返回到调用类({{1 }})。我已经覆盖了UITextField的关键弹出窗口。
ViewController.m
有一个XIB,但 ViewController
没有。 UITextField Touch Down映射到 CatagoryTableViewController
方法。
顺便说一句,SFCLog定义为:
catagoryFieldPressed
我在define SFCLog(FORMAT, ...) fprintf(stderr,"%s [line %d] %s\n",__PRETTY_FUNCTION__, __LINE__,[[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String])
中的每个方法的开头放置了SFCLog日志(NSLog的变体),并且只调用了init。关于我缺少的任何想法?
来自CatagoryTableViewController
(调用类标题)
ViewController.h
来自@interface ViewController : UIViewController <UITextFieldDelegate>
{
Word *currentWord;
NSMutableArray *words;
int wordsIndex;
int viewState;
int correctCounter;
int incorrectCounter;
}
(通话类)
ViewController.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;
}
根据Phillip Mills的帖子添加NSLog后编辑的调试控制台输出。
[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]
在AppDelegate.m之前
-[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;
}
答案 0 :(得分:0)
在Phillip Mills的帮助下发现了这个问题。调用UITableView的视图控制器未正确添加到导航堆栈中。它已被实例化,然后通过UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
添加到navigationController,但导航控制器本身未正确添加到tabBarController。
请参阅上面的AppDelegate.m之前和之后的版本。
感谢Phillip的帮助。