У меня есть вид входа в систему и после проверки имени пользователя я хочу перейти к представлению таблицы.
Я загрузил приложение SimpleDrillDown из примеров кода Apple, и я хочу, чтобы при запуске приложения сначала отображалась страница входа, а затем TableView.
Если у кого-то есть время, проект можно найти здесь:
http://developer.apple.com/iphone/library/samplecode/SimpleDrillDown/index.html
Изменения, которые я сделал:
SimpleDrillDownAppDelegate.m
import "SimpleDrillDownAppDelegate.h"
import "RootViewController.h"
import "LoginViewController.h"
import "DataController.h"
@implementation SimpleDrillDownAppDelegate
@synthesize window;
@synthesize navigationController;
@synthesize rootViewController;
@synthesize loginViewController;
@synthesize dataController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
//thomas add this
LoginViewController *_loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:[NSBundle mainBundle]];
self.loginViewController = _loginViewController;
// [_loginViewController release];
//
//thomas add this
// Create the data controller.
//DataController *controller = [[DataController alloc] init];
// self.dataController = controller;
// [controller release];
//rootViewController.dataController = dataController;
/*
The navigation and root view controllers are created in the main nib file.
Configure the window with the navigation controller's view and then show it.
*/
//thomas commented this and copy this into LoginView
//[window addSubview:[navigationController view]];
//thomas add this
[window addSubview:[loginViewController view]];
//thomas add this
[window makeKeyAndVisible];
}
- (void)dealloc {
//[navigationController release];
//[rootViewController release];
[loginViewController release];
[window release];
//[dataController release];
[super dealloc];
}
@end
SimpleDrillDownAppDelegate.h
@class DataController;
@class RootViewController;
@class LoginViewController;
@interface SimpleDrillDownAppDelegate : NSObject {
UIWindow *window;
UINavigationController *navigationController;
RootViewController *rootViewController;
LoginViewController *loginViewController;
DataController *dataController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) IBOutlet RootViewController *rootViewController;
@property (nonatomic, retain) IBOutlet LoginViewController *loginViewController;
@property (nonatomic, retain) DataController *dataController;
@end
LoginViewController.h
#import
@class DataController;
@class RootViewController;
@class LoginViewController;
@interface LoginViewController : UIViewController {
DataController *dataController;
IBOutlet UITextField *usernameField;
IBOutlet UITextField *passwordField;
IBOutlet UIButton *loginButton;
IBOutlet UIActivityIndicatorView *loginIndicator;
UINavigationController *navigationController;
RootViewController *rootViewController;
}
@property (nonatomic, retain) UITextField *usernameField;
@property (nonatomic, retain) UITextField *passwordField;
@property (nonatomic, retain) UIButton *loginButton;
@property (nonatomic, retain) UIActivityIndicatorView *loginIndicator;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) DataController *dataController;
@property (nonatomic, retain) IBOutlet RootViewController *rootViewController;
- (IBAction) login: (id) sender;
@end
LoginViewController.m
#import "LoginViewController.h"
#import "DataController.h"
#import "RootViewController.h"
@implementation LoginViewController
@synthesize usernameField;
@synthesize passwordField;
@synthesize loginButton;
@synthesize loginIndicator;
@synthesize navigationController;
@synthesize dataController;
@synthesize rootViewController;
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
- (IBAction) login: (id) sender
{
// TODO: spawn a login thread
NSString *userName = usernameField.text;
NSString *pass = passwordField.text;
loginIndicator.hidden = FALSE;
[loginIndicator startAnimating];
loginButton.enabled = FALSE;
//Hardcode here the credentials
if ([userName isEqualToString: @"test"] && [pass isEqualToString: @"test"]){
// Create the data controller.
DataController *controller = [[DataController alloc] init];
self.dataController = controller;
[controller release];
rootViewController.dataController = dataController;
[self pushViewController:self.navigationController animated:YES];
}else{
printf("ERROR");
}
}
@end
Наконец-то я получаю эту ошибку
Журнал ошибок
2010-02-24 21:19:55.595 SimpleDrillDown[97651:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[LoginViewController pushViewController:animated:]: unrecognized selector sent to instance 0x190d8a0'
2010-02-24 21:19:55.595 SimpleDrillDown[97651:207] Stack: (
807902715,
2501092617,
808284155,
807854166,
807706786,
18813,
814709201,
815110321,
815119058,
815114808,
814812979,
814722763,
814748641,
839148405,
807687520,
807683624,
839142449,
839142646,
814752238,
9140,
8994
)
Извините за длинный пост, но я не знаю, где еще искать. Я прочитал тон поста здесь: (
Заранее спасибо всем вам