table二级菜单效果,雪花效果

网上收集的或自己写的一些代码,记录下来,以后复习

记录下来以备以后有用

//

//  TableMenuViewController.h

//  TableMenu

//

//  Created by apple on 10-11-12.

//  Copyright 2010 __MyCompanyName__. Allrights reserved.

//

#import<UIKit/UIKit.h>

@interface TableMenuViewController :UIViewController<UITableViewDelegate,UITableViewDataSource>{

NSMutableArray *itemArray;

NSMutableArray *openItemArray;

//UITableView *menuTable;

}

@property(nonatomic,retain) NSMutableArray *itemArray;

@property(nonatomic,retain) NSMutableArray *openItemArray;

//@property (nonatomic,retain) IBOutlet UITableView*menuTable;

-(void)readPlistToArray;

@end

//

//  TableMenuViewController.m

//  TableMenu

//

//  Created by apple on 10-11-12.

//  Copyright 2010 __MyCompanyName__. Allrights reserved.

//

#import "TableMenuViewController.h"

@implementation TableMenuViewController

@synthesize itemArray;

@synthesize openItemArray;

//@synthesize menuTable;

// Implement viewDidLoad to do additional setup after loadingthe view, typically from a nib.

- (void)viewDidLoad {

   [super viewDidLoad];

self.itemArray =[NSMutableArrayarrayWithCapacity:0] ;

self.openItemArray= [NSMutableArrayarrayWithCapacity:0] ;

[selfreadPlistToArray];

}

-(void)readPlistToArray

{

if ([self.itemArraycount]) {

[self.itemArrayremoveAllObjects] ;

}

NSString * path=[[NSBundle mainBundle]pathForResource:@"MenuOrder"ofType:@"plist"] ;

NSArray*dicArray=[NSArrayarrayWithContentsOfFile:path];

//一级菜单

for (int i = 0 ; i< [dicArray count]; i++) {

NSMutableDictionary * menuDic_1 =[NSMutableDictionarydictionaryWithCapacity:0];

[menuDic_1 setObject:@"0"forKey:@"level"] ;

[menuDic_1 setObject:[[dicArrayobjectAtIndex:i]objectAtIndex:0]forKey:@"name"] ;

[self.itemArrayaddObject:menuDic_1] ;

if(![self.openItemArraycount]) {

//如果没有打开项

continue ;

}

//判断打开的菜单

for (int j = 0 ; j< [self.openItemArraycount]; j++) {

if([[[self.openItemArrayobjectAtIndex:j]objectForKey:@"name"] 

isEqualToString:[[dicArrayobjectAtIndex:i]objectAtIndex:0] ]) {

//二级菜单

NSArray *twoDic = [dicArrayobjectAtIndex:i] ;

for (int k = 1 ; k< [twoDic count] ; k++) {

NSMutableDictionary * menuDic_2 =[NSMutableDictionarydictionaryWithCapacity:0];

[menuDic_2 setObject:@"2"forKey:@"level"] ;

[menuDic_2 setObject:[twoDicobjectAtIndex:k]forKey:@"name"] ;

[self.itemArrayaddObject:menuDic_2] ;

}

}

}

}

}

#pragma mark -

#pragma mark Table view data source

// Customize the number of sections in the table view.

-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView {

return 1;

}

// Customize the number of rows in the table view.

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{

    return[self.itemArray count];

}

- (NSInteger)tableView:(UITableView*)tableView 

indentationLevelForRowAtIndexPath:(NSIndexPath*)indexPath

{

NSInteger tempInt =[[[self.itemArrayobjectAtIndex:[indexPath row]]objectForKey:@"level"] intValue ];

if (tempInt == 2) {

return 10;

}else {

return 0;

}

//return [[[self.itemArray objectAtIndex:[indexPath row]]objectForKey:@"level"] intValue];

}

// Customize the appearance of table view cells.

- (UITableViewCell*)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath {

    staticNSString *CellIdentifier = @"Cell";

   UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:CellIdentifier];

    //if (cell ==nil) {

cell = [[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier]autorelease];

    //}

NSDictionary *dic =[self.itemArrayobjectAtIndex:[indexPath row]] ;

if(![[dicobjectForKey:@"level"]intValue])//菜单项

{

//如果为0则为主菜单

cell.selectionStyle =UITableViewCellSelectionStyleGray ;

UIImageView*menubackView=[[UIImageView alloc]initWithImage:[UIImageimageNamed:@"menubackgroud.png"]];

[cell setBackgroundView:menubackView];

cell.textLabel.text = [dicobjectForKey:@"name"];

}// Configure the cell.

else {

cell.selectionStyle =UITableViewCellSelectionStyleBlue ;

cell.textLabel.text = [dicobjectForKey:@"name"];

UIImageView*menubackView=[[UIImageView alloc]initWithImage:[UIImageimageNamed:@"itembackgroud.png"]];

[cell setBackgroundView:menubackView];

}

    returncell;

}

#pragma mark -

#pragma mark Table view delegate

- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {

NSInteger row=[indexPath row];

NSDictionary *dic =[self.itemArrayobjectAtIndex:row] ;

NSString *key=[dicobjectForKey:@"name"];

if(![[dicobjectForKey:@"level"]intValue])

{

//如果为0则为主菜单

for (int i = 0 ; i< [self.openItemArraycount]; i++) {

if([[[self.openItemArrayobjectAtIndex:i]objectForKey:@"name"]isEqualToString:key]) {

if ([keyisEqualToString:@"全部拍卖品"]){

NSLog(@"选中"全部拍卖品"");

}

[self.openItemArrayremoveObjectAtIndex:i] ;

[self readPlistToArray];

//[self.menuTable reloadData] ;

[tableView reloadData];

return ;

}

}

//

[self.openItemArrayaddObject:dic] ;

[self readPlistToArray];

//[self.menuTable reloadData] ;

[tableView reloadData];

}

else {

//如果是菜单项处理相关操作

NSLog(@"按在:%@",key);

}

}

- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath

{

return 66;

}

- (void)didReceiveMemoryWarning {

// Releases the view if it doesn't have a superview.

   [superdidReceiveMemoryWarning];

// 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 {

[itemArray release];

[openItemArrayrelease];

// [menuTable release];

    [superdealloc];

}

@end

雪花效果

//

//  SonwViewController.h

//  Sonw

//

//  Created by daniel hou on 11/29/10.

//  Copyright heng-tus-imac: 2010. All rightsreserved.

//

#import<UIKit/UIKit.h>

@interface SonwViewController : UIViewController{

UIImage * flakeImage;

}

@property (nonatomic ,retain) UIImage *flakeImage;

-(void)onTimer;

-(void)onAnimationComplete:(NSString*)animationID finished:(NSNumber *)finishedcontext:(void *)context;

@end

//

//  SonwViewController.m

//  Sonw

//

//  Created by daniel hou on 11/29/10.

//  Copyright heng-tus-imac: 2010. All rightsreserved.

//

#import "SonwViewController.h"

@implementation SonwViewController

@synthesize flakeImage;

- (void)viewDidLoad {

[super viewDidLoad];

// set the background color to something COLD

self.view.backgroundColor= [UIColorcolorWithRed:0.1green:0.3blue:0.5alpha:1.0];

// load our flake image we will use the same image over andover

flakeImage = [UIImageimageNamed:@"flake.png"];

// start a timet that will fire 20 times per second

[NSTimerscheduledTimerWithTimeInterval:(0.05)target:selfselector:@selector(onTimer)userInfo:nilrepeats:YES];

}

// Timer event is called whenever the timer fires

- (void)onTimer

{

// build a view from our flake image

UIImageView* flakeView = [[UIImageViewalloc]initWithImage:flakeImage];

// use the random() function to randomize up our flakeattributes

int startX =round(random() % 320);

//int startY = round(random() % 480);

int endX = round(random()% 320);

double scale = 1 /round(random() % 100) +1.0;

double speed = 1 /round(random() % 100) +1.0;

// set the flake start position

flakeView.frame = CGRectMake(startX,-80, 25.0 * scale, 25.0 *scale);

flakeView.alpha = 1.0;

// put the flake in our main view

[self.viewaddSubview:flakeView];

[UIViewbeginAnimations:nilcontext:flakeView];

// set up how fast the flake will fall

[UIViewsetAnimationDuration:5 *speed];

// set the postion where flake will move to

flakeView.frame = CGRectMake(endX,500.0, 25.0 * scale, 25.0 *scale);

// set a stop callback so we can cleanup the flake when itreaches the

// end of its animation

[UIViewsetAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];

[UIViewsetAnimationDelegate:self];

[UIViewcommitAnimations];

}

- (void)onAnimationComplete:(NSString*)animationID finished:(NSNumber *)finishedcontext:(void *)context {

UIImageView *flakeView = context;

[flakeView removeFromSuperview];

// open the debug log and you will see that all flakes have aretain count 

// of 1 at this point so we know the release below will keep ourmemory 

// usage in check

//NSLog([NSString stringWithFormat:@"[flakeView retainCount] =%d", [flakeView retainCount]]);

[flakeView release];

}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{

// Return YES for supported orientations

return(interfaceOrientation ==UIInterfaceOrientationPortrait);

}

- (void)didReceiveMemoryWarning {

[superdidReceiveMemoryWarning]; // Releases theview if it doesn't have a superview

// Release anything that's not essential, such as cacheddata

}

- (void)dealloc {

[flakeImage release];

[super dealloc];

}

@end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值