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

时间:2017-07-19 14:02:14

标签: ios objective-c iphone appdelegate

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

Login app to mysql DB [part 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。 我创建了LoginTableTableViewController.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

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

enter image description here

执行会停止主类函数的某些线程上的程序如何删除此错误并获得所需的输出?您可以从此链接下载示例代码进行更正。https://drive.google.com/file/d/0B5pNDpbvZ8SnV3Zab3VPM1B0a0k/view?usp=sharing

1 个答案:

答案 0 :(得分:1)

您的项目仍在指定应加载“主”故事板。编辑Info.plist文件以删除故事板条目,它将使您超过当前错误。

(如果在提问时从调试控制台中包含错误消息,那么任何试图提供帮助的人都会更容易。例如:“因未捕获的异常而终止应用程序'NSInvalidArgumentException',原因:'无法找到一个名为“Main”的故事板“。)