UITransitionView problem

Discussion in 'iOS Development' started by dunkel, May 8, 2008.

  1. dunkel

    dunkel New Member

    Joined:
    Apr 29, 2008
    Messages:
    7
    Likes Received:
    0
    Hi there guys, i am writing my own application and i have a problem with the UITransitionView, look this is what i have.

    I have a main class called "icontrol" this clas create an instance of other class i have called "MainView" which is a UIView child inside MainView i have a navbar and a IUTable, the UITable object is a class that i create so it is a class inerithed from the UITable class, that table has some options, what i need is to change the MainView objecto for SecondView or ThirdView object when i select a specific option, so the question is: How can I call an UITransitionView object or where do i set it, because i set it in the UITable class and what it do when i try to transition views is that the new views are added to teh table, and that is not what i need :S

    i really need a little explanation of this because the book i am reading doesn't talk about this kind of problems.

    if you need to see some parts of the code just ask me for it i don't have any problem on pasting it here

    thank you

    Here is the source code of my files:

    Main.m

    Code:
    #import <UIKit/UIKit.h>
    #import "icontrol.h"
    
    int main(int argc, char **argv)
    {
    	int ret;
    
    	NSAutoreleasePool *pool	= [[NSAutoreleasePool alloc] init];
    
    	ret	= UIApplicationMain(argc, argv, [icontrol class]);
    
    	return ret;
    }
    
    icontrol.h
    Code:
    #import <CoreFoundation/CoreFoundation.h>
    #import <UIKit/UIKit.h>
    #import <UIKit/UIAlertSheet.h>
    #import <UIKit/UITransitionView.h>
    #import <Foundation/Foundation.h>
    #import "MainView.h"
    
    @interface icontrol : UIApplication {
    	UIWindow *window;
    	
    	/*mainView*/
    	MainView *mainView;
    	MainView *secondView;
    	
    }
    
    - (void) applicationDidFinishLaunching: (NSNotification *)aNotification;
    
    @end
    
    icontrol.m
    Code:
    #import <CoreGraphics/CGColor.h>
    #import <UIKit/UINavigationBar.h>
    #import <UIKit/UINavigationItem.h>
    #import "icontrol.h"
    
    @implementation icontrol
    
    
    - (void) applicationDidFinishLaunching: (NSNotification *)aNotification
    {
    	NSLog(@"Iniciando\n");
    
    	window	= [[UIWindow alloc] initWithContentRect: [ UIHardware fullScreenApplicationContentRect ]];
    
    	
    	CGRect rect = [ UIHardware fullScreenApplicationContentRect ];
    	rect.origin.x = rect.origin.y = 0.0f;
    	
    	mainView = [[MainView alloc] initWithFrame: rect];	
    	secondView = [[MainView alloc] initWithFrame: rect];
    	
    	[window setContentView:mainView];
    	[window orderFront: self];
    	[window makeKey: self];
    	[window _setHidden: NO];
    
    }
    
    
    - (void)sendString:(char *)cadena
    {
    	
    }
    
    @end
    
    MainView.h
    Code:
    #import <UIKit/UIKit.h>
    #import "LstCategorias.h"
    
    
    @interface MainView : UIView{
    	LstCategorias *categorias;
    	UIAlertSheet *alertSheet;
    }
    
    - (id)initWithFrame:(CGRect)rect;
    - (void)dealloc;
    
    
    @end
    MainView.m
    Code:
    #import "MainView.h";
    
    @implementation MainView
    - (id)initWithFrame:(CGRect)rect {
    
        if ((self == [ super initWithFrame: rect ]) != nil) {
    
            float blanco[4] = {1.0f,1.0f,1.0f,1.0f};
    	self.backgroundColor = CGColorCreate(CGColorSpaceCreateDeviceRGB(), blanco);
    
    	UINavigationBar *navBar	= [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)];
    	/*[navBar showButtonsWithLeftTitle: @"Config" rightTitle: @"About" leftBack: false];*/
    	[navBar setBarStyle: 1];
    	[navBar enableAnimation];
    	[navBar showLeftButton:@"Config" withStyle:0 rightButton:@"About" withStyle:0];
    	[navBar setDelegate: self];
    
    	UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:@"RED HOUSE"];
    	[navBar pushNavigationItem: navItem];
    
    	/*CATEGORIAS*/
    	NSLog(@"Adding Table");
    	CGRect rect2 = [ UIHardware fullScreenApplicationContentRect ];
    	rect2.origin.x = 0.0f;
    	rect2.origin.y = 44.0f;
    	categorias = [ [ LstCategorias alloc ] initWithFrame: rect2 ];
    	[self addSubview: categorias];
    	[categorias reloadData];
    	NSLog(@"Table Added");
    
    	[self addSubview: navBar];
    
        }
    
        return self;
    }
    
    - (void)dealloc
    {
        /* Deallocate any resources here */
    
        [ self dealloc ];
        [ super dealloc ];
    }
    
    - (void) navigationBar: (UINavigationBar *)navBar buttonClicked:(int)button 
    {
    	switch (button) 
    	{
    		case 0:
    			NSLog(@"Alerta");
    			alertSheet = [[UIAlertSheet alloc] initWithFrame: CGRectMake(0, 240, 320, 240)];
    			[ alertSheet setTitle:@"RED HOUSE iControl v0.1-4a" ];
    			[ alertSheet setBodyText: [ NSString stringWithFormat: @"Developed by: Dunkel" ]];
    			[ alertSheet setDelegate: self ];
    			[ alertSheet setAlertSheetStyle: 0 ];
    			[ alertSheet setDestructiveButton:[ alertSheet addButtonWithTitle:@"OK" ]];
    			[ alertSheet presentSheetInView: self ];
    
    		break;
    		case 1:
    			NSLog(@"Config.");
    		break;
    		default:
    			NSLog(@"Should never reach here");
    	}
    }
    
    
    - (void)alertSheet:(UIAlertSheet *)sheet buttonClicked:(int)button
    {
    	[ sheet dismiss ];
    }
    
    @end
    
    LstCategorias.h
    Code:
    #import <UIKit/UIKit.h>
    #import <UIKit/UISimpleTableCell.h>
    #import <UIKit/UITableColumn.h>
    #import <UIKit/UIImageAndTextTableCell.h>
    #import <UIKit/UIImage.h>
    
    #import "Socket.h"
    
    @interface LstCategorias : UITable
    {
    	UITableColumn *myColumn;
    	NSMutableArray *lstCat;
    	NSMutableArray *lstCatImg;
    	NSMutableArray *lstCatCad;
    
    	Socket *socket;
    }
    -(void)sendString:(NSString *)cadena;
    -(id)initWithFrame:(struct CGRect)rect;
    -(void)dealloc;
    
    -(int)numberOfRowsInTable:(UITable *)_table;
    -(UITableCell *)table:(UITable *)table cellForRow:(int)row column:(UITableColumn *)col;
    
    -(void)reloadData;
    @end
    LstCategorias.m
    Code:
    #import "LstCategorias.h"
    #import "MainView.h"
    
    @implementation LstCategorias
    	
    -(id)initWithFrame:(struct CGRect)rect{
    
    	if ((self == [ super initWithFrame: rect ]) != nil) {
    		NSLog(@"1\n");
    		myColumn = [ UITableColumn alloc ];
    		NSLog(@"2\n");		
    		[ myColumn 
    			initWithTitle:  @"Column 1"
    			identifier: @"column1"
    			width: rect.size.width
    		];
    		NSLog(@"3\n");
    		[ self addTableColumn: myColumn ];
    		NSLog(@"4\n");
    		[ self setDataSource:self];
    		NSLog(@"5\n");
    		[ self setSeparatorStyle: 1 ];
    		[ self setDelegate: self ];
    		[ self setRowHeight: 64 ];
    		NSLog(@"6-end\n");
    		
    		lstCat = [[NSMutableArray alloc] init];
    		lstCatImg = [[NSMutableArray alloc] init];
    		lstCatCad = [[NSMutableArray alloc] init];
    
    	}
    	return self;
    }
    
    -(void)reloadData{
    	NSLog(@"Remove categories list elements\n");
    	[lstCat removeAllObjects];
    	[lstCatImg removeAllObjects];
    	
    	NSLog(@"Insert Elements");
    
    	[lstCat addObject:@"Automatizacion"];	
    	[lstCat addObject:@"Escenarios"];	
    	[lstCat addObject:@"Iluminacion"];	
    	[lstCat addObject:@"Seguridad"];
    
    	[lstCatImg addObject:@"test.png"];	
    	[lstCatImg addObject:@"test.png"];
    	[lstCatImg addObject:@"test.png"];
    	[lstCatImg addObject:@"seguridad.png"];
    
    	/*TEMPORAL-START*/
    	[lstCatCad addObject:@"*1*1*13##"];	
    	[lstCatCad addObject:@"*1*1*37##"];	
    	[lstCatCad addObject:@"*1*1*47##"];	
    	[lstCatCad addObject:@"*1*1*42##"];
    	/*TEMPORAL-END*/
    
    	[super reloadData];
    }
    
    -(void)dealloc{
    	NSLog(@"LstCategorias: dealloc method - start\n");
    	[myColumn release];
    	[super dealloc];
    	NSLog(@"LstCategorias: dealloc method - end\n");
    }	
    
    -(int)numberOfRowsInTable:(UITable *)_table{
    	NSLog(@"number of rows start\n");
    	return [lstCat count];
    }
    
    -(UITableCell *)table:(UITable *)table cellForRow:(int)row column:(UITableColumn *)col{
    	NSLog(@"cells-start\n");	
    	NSString *title;
    	/*title = [[NSString alloc] initWithFormat:@"Row %d", row];*/
    	title = [ lstCat objectAtIndex: row];
    	/*title = [[NSString alloc] initWithCString:[ lstCat objectAtIndex: row] encoding:NSISOLatin1StringEncoding];*/
    	UIImageAndTextTableCell *cell = [ [ UIImageAndTextTableCell alloc ] init ];
    	UIImageView *image = [UIImage applicationImageNamed:[ lstCatImg objectAtIndex: row] ];
    	[ cell setTitle: title ];
    	[ cell setImage: image ];
    	[ cell setAlignment: 0 ];
    	[ cell setShowDisclosure: YES ];
    	[ cell setDisclosureStyle: 1 ];
    
    	return [cell autorelease];
    }
    
    - (void)tableRowSelected:(NSNotification *)notification
    {
    	int index = [ self selectedRow ];
    	NSLog(@"Seleccionada");
    	/*[ self sendString:[ lstCatCad objectAtIndex: index ] ];*/
    
    	/********************************
            **  HERE I NEED TO CHANGE MY VIEWS
            *********************************/
    }
    
    - (void)sendString:(NSString *)cadena
    {
    	NSLog(@"Entro a sendString\n");
    	socket = [Socket socket];
    	NSLog(@"Inicializo el socket\n");
    	[socket connectToHostName:@"192.168.1.35" port:20000];
    	NSLog(@"Me conecto al host\n");
    	[socket writeString:@"*99*0##"];
    	[socket writeString:cadena];
    	NSLog(@"Envio la cadena\n");
    	NSMutableData *response = [NSMutableData data];
    	NSLog(@"Recibo respuesta\n");
    	[[NSFileHandle fileHandleWithStandardOutput] writeData:response];
    	NSLog(@"Salgo de sendString\n");
    }
    
    @end

Share This Page