gpt4 book ai didi

ios - AppDelegate 函数未加载 TableView Controller

转载 作者:行者123 更新时间:2023-11-29 00:16:29 25 4
gpt4 key购买 nike

我创建了简单的 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

最佳答案

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

(如果您在提问时包含来自调试控制台的错误消息,那么任何试图提供帮助的人都会更容易。例如:“由于未捕获的异常‘NSInvalidArgumentException’而终止应用程序,原因:‘Could not在 bundle 中找到名为“Main”的 Storyboard"。)

关于ios - AppDelegate 函数未加载 TableView Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45192933/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com