繁体   English   中英

AppDelegate函数未加载表视图控制器

[英]AppDelegate function is not loading Table view controller

我创建了用于登录的简单Master Detail应用程序,并根据本教程删除了MasterViewController,DetailViewController和Main.storyboard:

登录应用程序到mysql DB [第1部分]

在AppDelegate didFinishLaunchingWithOptions函数中,我进行了以下更改

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds] ];

    /*UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
     UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
     navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;*/

    LoginTableViewController *loginTableViewController=[[LoginTableViewController alloc]initWithNibName:@"LoginTableViewController" bundle:nil ];

    self.navigationController =[[UINavigationController alloc]initWithRootViewController:loginTableViewController];

    self.window.rootViewController=self.navigationController;
    [self.window makeKeyWindow];

    return YES;
}

我从App Delegate功能评论了此功能

  /*
    - (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController {
.............................

    }*/

我使用子类UITableViewController的xib创建了LoginTableTableViewController。 我创建了LoginTableTableViewViewController.h

 #import "LoginTableViewController.h"

@interface LoginTableViewController ()

@end

@implementation LoginTableViewController
@synthesize arraylogin,userNameTextField,passwordTextField;
bool isKeyboardVisible=FALSE;

- (void)viewDidLoad {
    [super viewDidLoad];
    arraylogin=[[NSArray alloc] initWithObjects:@"user name",@"password",nil];
    //set title
    self.navigationItem.title=@"Best App";

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardAppeared) name:UIKeyboardDidShowNotification object:nil];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

-(void) loginAction
{
    if([userNameTextField.text isEqualToString:@""] || [passwordTextField.text isEqualToString:@""])
    {

        //   UIAlertView @alert=[[UIAlertView alloc] intitWithTitle:@"alert" messge:@"Please fill in all //the fields" delegate:self cancel]
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"alert" message:@"Please fill in all the fields" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert show];
        //i will use a code to connect to DB turorial

    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)keyboardAppeared
{
    if(isKeyboardVisible==false)
    {
        isKeyboardVisible=true;

        UIBarButtonItem *btnGo=[[UIBarButtonItem alloc] initWithTitle:@"Go" style:UIBarButtonItemStyleBordered target:self action:@selector(loginAction)];
        self.navigationItem.rightBarButtonItem=btnGo;
    }
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows

    return [arraylogin count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifer=@"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifer];

    if (cell==nil)
    {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifer];

    }
    //cell are not selectable
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    CGRect frame;
    frame.origin.x=10;
    frame.origin.y=10;
    frame.size.height=30 ;
    frame.size.width= 200;

    UILabel *label=[[UILabel alloc]initWithFrame:frame];

    label.font=[UIFont boldSystemFontOfSize:16.0];
    label.text=[arraylogin objectAtIndex:indexPath.row];
    [cell.contentView addSubview:label];

    frame.origin.x=110;
    frame.size.height=90 ;
    frame.size.width= 180;

    // Configure the cell
    if(indexPath.row==0)
    {//username part
        userNameTextField=[[UITextField alloc] initWithFrame:frame];

        userNameTextField.returnKeyType=UIReturnKeyDefault;
        [cell.contentView addSubview:userNameTextField];
    }
    else{//password part
        passwordTextField=[[UITextField alloc] initWithFrame:frame];
        passwordTextField.returnKeyType=UIReturnKeyDefault;
        passwordTextField.secureTextEntry=YES;
        [cell.contentView addSubview:passwordTextField];
    }
    return cell;
}


/*
 // Override to support conditional editing of the table view.
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the specified item to be editable.
 return YES;
 }
 */

/*
 // Override to support editing the table view.
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
 if (editingStyle == UITableViewCellEditingStyleDelete) {
 // Delete the row from the data source
 [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
 } else if (editingStyle == UITableViewCellEditingStyleInsert) {
 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
 }
 }
 */

/*
 // Override to support rearranging the table view.
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
 }
 */

/*
 // Override to support conditional rearranging of the table view.
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the item to be re-orderable.
 return YES;
 }
 *
 /

 /*
 #pragma mark - Table view delegate

 // In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 // Navigation logic may go here, for example:
 // Create the next view controller.
 <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:<#@"Nib name"#> bundle:nil];

 // Pass the selected object to the new view controller.

 // Push the view controller.
 [self.navigationController pushViewController:detailViewController animated:YES];
 }
 */
-(void) viewDidUnload
{
    [super viewDidUnload];
    self.arraylogin=nil;
    self.userNameTextField=nil;
    self.passwordTextField=nil;
}
/*
 #pragma mark - Navigation

 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end

该程序应该正在执行并像此图所示显示

在此处输入图片说明

执行会在主类函数的某个线程上停止程序,我如何才能消除此错误并获得所需的输出? https://drive.google.com/file/d/0B5pNDpbvZ8SnV3Zab3VPM1B0a0k/view?usp=sharing

您的项目仍在指定应加载“主”情节提要。 编辑您的Info.plist文件以删除情节提要条目,它将使您摆脱当前的错误。

(如果在询问问题时包含来自调试控制台的错误消息,则它会使尝试寻求帮助的人更容易。例如:“ 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'找不到名为'Main的故事板“在捆绑中 ”。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM