UI界面不显示

//
//  ZYPAppDelegate.m
//  UIindex8.21wan
//
//  Created by lanouhn on 14-8-21.
//  Copyright (c) 2014年 亚鹏大神. All rights reserved.
//

#import "ZYPAppDelegate.h"
#import "ltview.h"




@interface ZYPAppDelegate ()



{
    UIView*_containerView;
    NSMutableArray*_ltViewArr;
    ltview*_user;
    ltview*_password;
}


@end

@implementation NSObject (uinew)

+(id)uilableWithX:(CGFloat)x y:(CGFloat)y width:(CGFloat)width height:(CGFloat)height backcolor:(UIColor*)backcolor borderWidth:(CGFloat)borderWidth lableText:(NSString*)lableText superView:(UIView*)superView
{
    UILabel*newlable = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    newlable.backgroundColor = backcolor;
    newlable.layer.borderWidth = borderWidth;
    newlable.text = lableText;
    newlable.textAlignment = NSTextAlignmentCenter;
    [superView addSubview:newlable];
    [newlable release];
    return newlable;
    
}

+(id)uiTextfieldWithX:(CGFloat)x y:(CGFloat)y width:(CGFloat)width height:(CGFloat)height backcolor:(UIColor*)backcolor borderWidth:(CGFloat)borderWidth defultText:(NSString*)defultText textAligen:(NSTextAlignment)textAligen fontColor:(UIColor*)fontColor fontSize:(CGFloat)fontSize keyboard:(UIKeyboardType)keyboard returnType:(UIReturnKeyType)returnType superView:(UIView*)superView canedit:(BOOL)canedit
{
    UITextField *newTextField = [[UITextField alloc] initWithFrame:CGRectMake(x, y, width, height)];
    newTextField.backgroundColor = backcolor;
    newTextField.layer.borderWidth = borderWidth;
    newTextField.placeholder = defultText;
    newTextField.textAlignment = textAligen;
    newTextField.textColor = fontColor;
    newTextField.font = [UIFont systemFontOfSize:fontSize];
    newTextField.keyboardType = keyboard;
    newTextField.returnKeyType = returnType;
    newTextField.enabled = canedit;
    [superView addSubview:newTextField];
    newTextField.borderStyle = UITextBorderStyleRoundedRect;
    newTextField.layer.cornerRadius = 10;
    [newTextField release];
    return  newTextField;
    
}

+(id)uibuttonX:(CGFloat)x y:(CGFloat)y width:(CGFloat)width height:(CGFloat)height backcolor:(UIColor*)backcolor borderWidth:(CGFloat)borderWidth buttonText:(NSString*)buttonText  fontColor:(UIColor*)fontColor fontSize:(CGFloat)fontSize eventdoner:(id)eventdoner eventAct:(SEL)eventAct eventTime:(UIControlEvents)eventTime superView:(UIView*)superView
{
    UIButton *newButton = [UIButton buttonWithType:UIButtonTypeSystem];
    newButton.frame = CGRectMake(x, y, width, height);
    newButton.backgroundColor = backcolor;
    newButton.layer.borderWidth = borderWidth;
    [newButton setTitle:buttonText forState:UIControlStateNormal];
    newButton.titleLabel.font = [UIFont systemFontOfSize:fontSize];
    //    newButton.titleLabel.textColor = fontColor;
    [newButton setTitleColor:fontColor forState:UIControlStateNormal];
    newButton.layer.cornerRadius = 10;
    newButton.layer.masksToBounds = YES;
    [newButton addTarget:eventdoner action:eventAct forControlEvents:eventTime];
    [superView addSubview:newButton];
    return newButton;
    
    
}


@end




@implementation ZYPAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
   
    UIView*container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
    container.backgroundColor = [UIColor redColor];
    
    [self.window addSubview:container];
    [container release];
    
    
    [self indexViewsuperView:container];
    
    
    
    
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
-(void)dealloc{
    [_window dealloc];
    [super dealloc];
}
-(void)indexViewsuperView:(UIView*)superview
{
    UIView*index = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
    index.backgroundColor = [UIColor redColor];
    [superview addSubview:index];
//    [index release];
    
    ltview*user = [[ltview alloc] initWithFrame:CGRectMake(20, 50, 270, 80) lableText:@"user:" placeholder:@"please enter here"];
    [index addSubview:user];
    [index setBackgroundColor:[UIColor whiteColor]];
    [user setDelegate:self];
    [_ltViewArr addObject:user];
    _user = user;
    [user release];
    
    ltview*password = [[ltview alloc] initWithFrame:CGRectMake(20, 200, 270, 80) lableText:@"password:" placeholder:@"please enter here"];
    [password setBackgroundColor:[UIColor whiteColor]];
    [index addSubview:password];
    [_ltViewArr addObject:password];
    [password setSecureEntry:YES];
    [password setDelegate:self];
    _password = password;
    [password release];
    
    UIButton*sure = [UIButton uibuttonX:30 y:330 width:250 height:90 backcolor:[UIColor whiteColor] borderWidth:1 buttonText:@"sure" fontColor:[UIColor blackColor] fontSize:20 eventdoner:self eventAct:@selector(sureOfIndex:) eventTime:UIControlEventTouchUpInside superView:index];
    
    UIButton*cancle = [UIButton uibuttonX:30 y:450 width:250 height:90 backcolor:[UIColor whiteColor] borderWidth:1 buttonText:@"cancle" fontColor:[UIColor blackColor] fontSize:20 eventdoner:self eventAct:@selector(cancleOfIndex:) eventTime:UIControlEventTouchUpInside superView:index];
    
    [superview addSubview:index];
    [index release];
}


-(void)sureOfIndex:(UIButton*)btn
{
    if ([_user.text isEqualToString:@"lanoukeji"]&&[_password.text isEqualToString:@"123456"]) {
        UIAlertView *welcome = [[UIAlertView alloc] initWithTitle:@"welcome" message:@"to back!!!!" delegate:self cancelButtonTitle:@"cancle" otherButtonTitles:@"sure", nil];
        [welcome show];
        [welcome release];
    }else
    {
        UIAlertView*error=[[UIAlertView alloc] initWithTitle:@"user or" message:@"password is error" delegate:self cancelButtonTitle:@"cancle" otherButtonTitles:@"sure", nil];
        [error show];
        [error release];
      
       
    }
 
 
}
-(void)cancleOfIndex:(UIButton*)btn
{
    
    
    
    
    
    
 
 
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
   
   
}





@end







经过分析,发现如下代码有问题:

-(void)indexViewsuperView:(UIView*)superview
{
    UIView*index = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
    index.backgroundColor = [UIColor redColor];
    [superview addSubview:index];
//    [index release];

这里

过度释放了,注掉,OK,可以运行

你可能感兴趣的:(UI界面不显示)