Allora nella nuova view quella che devo far comparire non c'è uno xib il problema è che non so collegare il sistema di login ai contenuti della app posto il codice per intero
mainview.h
#import <UIKit/UIKit.h>
#import "InsertDelegate.h"
__weak id <InsertDelegate> _delegate;
@interface MainView : UIView <UITextViewDelegate, UITextFieldDelegate, UITableViewDataSource,UITableViewDelegate>{
UINavigationController * Controller;
}
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIButton *btnLogout;
@property (nonatomic, strong) UIButton *btnLogout2;
@property(nonatomic,weak) id <InsertDelegate> delegate;
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, retain) UINavigationController * Controller;
-(IBAction)startDownload:(id)sender;
- (id) initWIthNavigationController:(UINavigationController*)controller;
@end
questo il metodo richiamato dal pulsante
-(IBAction)startDownload:(id)sender{
qui leggo un xml lo inserisco in un NSDictionary lo metto negli array e passo questi array alla nuova view dove c'è una UITbleView che dev'essere popolata da questi array
il pulsante fa tutto tranne far visualizzare la nuova view
mainview.m
#import "MainView.h"
#import "ImageFactory.h"
#import "LoginNotificationNames.h"
#import "MainNotificationNames.h"
#import "DownloadViewController.h"
#import "MyBooxViewViewController.h"
#import "XMLReader.h"
@implementation MainView
@synthesize imageView = _imageView;
@synthesize btnLogout = _btnLogout;
@synthesize btnLogout2 = _btnLogout2;
@synthesize Controller;
- (id) initWIthNavigationController:(UINavigationController*)controller{
if (self = [super init]) {
self.Controller = controller;
// Initialization code
}
return self;
}
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self createBackground];
[self createLogoutButton];
[self createDownloadButton];
}
return self;
}
- (void)createBackground {
UIImage *image = [ImageFactory createImageWithPathForResource:@"bg" ofType:@"png" inDirectory:@"images"];
self.imageView = [[UIImageView alloc] initWithImage:image];
[self addSubview:self.imageView];
}
- (void)createLogoutButton {
UIImage *image = [ImageFactory createImageWithPathForResource:@"logout_button" ofType:@"png" inDirectory:@"images"];
self.btnLogout = [UIButton buttonWithType:UIButtonTypeCustom];
[self.btnLogout setImage:image forState:UIControlStateNormal];
self.btnLogout.frame = CGRectMake(25, 25, image.size.width, image.size.height);
[self.btnLogout addTarget:self action:@selector(logoutClicked:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.btnLogout];
}
- (void)createDownloadButton {
UIImage *image = [ImageFactory createImageWithPathForResource:@"logout_button" ofType:@"png" inDirectory:@"images"];
self.btnLogout2 = [UIButton buttonWithType:UIButtonTypeCustom];
[self.btnLogout2 setImage:image forState:UIControlStateNormal];
self.btnLogout2.frame = CGRectMake(25, 125, image.size.width, image.size.height);
[self.btnLogout2 addTarget:self action:@selector(startDownload:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.btnLogout2];
}
- (void)logoutClicked:(id)sender {
NSLog(@"[MainView] Logout clicked");
[[NSNotificationCenter defaultCenter] postNotificationName:LOGOUT_NOTIFICATION object:self];
}
- (void)dealloc {
NSLog(@"[MainView] Dealloc");
}
-(IBAction)startDownload:(id)sender{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"yesssssss what's up"
message:[NSString stringWithFormat:@"iPad %@", @"yes"]
//message:[NSString stringWithFormat:@"iPad %d", indexPath.row]
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
/////////////////////
NSString *url = @"http://miosito.com/ebooks/filexml.xml";
NSURLRequest *urlrequest = [ [NSURLRequest alloc] initWithURL: [NSURL URLWithString:url] ];
NSData *returnData = [ NSURLConnection sendSynchronousRequest:urlrequest returningResponse: nil error: nil ];
NSString *testXMLString = [[NSString alloc] initWithData:returnData encoding:NSASCIIStringEncoding];
// Parse the XML into a dictionary
NSError *parseError = nil;
NSDictionary *dict = [XMLReader dictionaryForXMLString:testXMLString error:&parseError];
NSMutableArray *ebook = [[NSMutableArray alloc] init];
ebook = [[dict valueForKey:@"eboox"] valueForKey:@"ebook"];
//Questo conterrà un array di dictionary, ogni dict è un utente
NSMutableArray *autore = [[NSMutableArray alloc] init];
NSMutableArray *titolo = [[NSMutableArray alloc] init];
NSMutableArray *urls = [[NSMutableArray alloc] init];
NSMutableArray *editore = [[NSMutableArray alloc] init];
NSMutableArray *anno = [[NSMutableArray alloc] init];
for (NSDictionary *user in ebook)
{
NSString *autoreString = [[user valueForKey:@"autore"] valueForKey:@"text"];
NSString *titoloString = [[user valueForKey:@"titolo"] valueForKey:@"text"];
NSString *urlsString = [[user valueForKey:@"url"] valueForKey:@"text"];
NSString *editoreString = [[user valueForKey:@"editore"] valueForKey:@"text"];
NSString *annoString = [[user valueForKey:@"anno"] valueForKey:@"text"];
[autore addObject:autoreString];
[titolo addObject:titoloString];
[urls addObject:urlsString];
[editore addObject:editoreString];
[anno addObject: annoString];
}
int count = [titolo count];
for(int i=0;i<count;i++)
{
id item1;
id item2;
id item3;
id item4;
id item5;
item1 = [titolo objectAtIndex:i];
item2 = [autore objectAtIndex:i];
item3 = [urls objectAtIndex:i];
item4 = [editore objectAtIndex:i];
item5 = [anno objectAtIndex:i];
NSLog(@"Found an Item: %@",item1);
NSLog(@"Found an Item: %@",item2);
NSLog(@"Found an Item: %@",item3);
NSLog(@"Found an Item: %@",item4);
NSLog(@"Found an Item: %@",item5);
}
//Prima istanzio il secondo controller, che nel suo costruttore si setta come delegato di se stesso
MyBooxViewViewController *viewController4 = [[MyBooxViewViewController alloc]init];
//Poi chiamo il metodo del delegato sull' istanza del secondo controller
[viewController4.delegate insertNewFruit: titolo: autore :editore: anno: urls];
//Infine pusho il controller
[self.Controller pushViewController:viewController4 animated:YES];
}
@end
la mainview funziona con un controller che fa parte del sistema di login posto questo codice
mainviewcontroller.h
#import <UIKit/UIKit.h>
@interface MainViewController : UIViewController
@end
mainviewcontroller.m
#import "MainViewController.h"
#import "MainView.h"
#import "LoginViewController.h"
#import "LoginNotificationNames.h"
#import "MainNotificationNames.h"
#import "DownloadViewController.h"
@interface MainViewController ()
@end
@implementation MainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
NSLog(@"[MainViewController] Init");
}
return self;
}
- (void)loadView {
CGRect frame = [[UIScreen mainScreen] bounds];
MainView *v = [[MainView alloc] initWithFrame:frame];
[self setView:v];
/////////push new view
//DownloadViewController *viewController2 = [[DownloadViewController alloc]initWithNibName:@"ViewController" bundle:nil];
//[self.navigationController pushViewController:viewController2 animated:YES];
///////////////////////
}
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"[MainViewController] View did load");
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutHandler:) name:LOGOUT_NOTIFICATION object:self.view];
}
- (void)viewDidAppear:(BOOL)animated {
BOOL isUserLoggedIn = [[NSUserDefaults standardUserDefaults] boolForKey:@"userLoggedIn"];
if( !isUserLoggedIn ){
[self showLoginViewAnimated:NO];
}
}
- (void)logoutHandler:(NSNotification *)notification {
NSLog(@"[MainViewController] Logout handler");
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"userLoggedIn"];
[[NSUserDefaults standardUserDefaults] synchronize];
[self showLoginViewAnimated:YES];
}
- (void)showLoginViewAnimated:(BOOL)animated {
NSLog(@"[MainViewController] Show login view controller");
LoginViewController *loginVC = [[LoginViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:loginVC animated:animated completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)dealloc {
NSLog(@"[MainViewController] Dealloc");
[[NSNotificationCenter defaultCenter] removeObserver:self name:LOGOUT_NOTIFICATION object:self.view];
}
@end
grazie dell'aiuto