网上收集的或自己写的一些代码,记录下来,以后复习
记录下来以备以后有用
//
//
//
//
//
//
//
#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
//
//
//
//
//
//
//
#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 {
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)numberOfSectionsInTableV
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
}
- (NSInteger)tableView:(UITableView*)tableView
indentationLevelForRowAt
{
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 {
cell = [[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefa
NSDictionary *dic =[self.itemArrayobjectAtIndex:[indexPath row]] ;
if(![[dicobjectForKey:@"level"]intValue])//菜单项
{
//如果为0则为主菜单
cell.selectionStyle =UITableViewCellSelection
UIImageView*menubackView=[[UIImageView alloc]initWithImage:[UIImageimageNamed:@"menubackgroud.png"]];
[cell setBackgroundView:menubackView];
cell.textLabel.text = [dicobjectForKey:@"name"];
}// Configure the cell.
else {
cell.selectionStyle =UITableViewCellSelection
cell.textLabel.text = [dicobjectForKey:@"name"];
UIImageView*menubackView=[[UIImageView alloc]initWithImage:[UIImageimageNamed:@"itembackgroud.png"]];
[cell setBackgroundView:menubackView];
}
}
#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.
// 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];
}
@end
雪花效果
//
//
//
//
//
//
//
#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
//
//
//
//
//
//
//
#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
[NSTimerscheduledTimerWithTimeIn
}
// 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
[UIViewsetAnimationDidStopSelec
[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)shouldAutorotateToInterf
// Return YES for supported orientations
return(interfaceOrientation ==UIInterfaceOrientationPo
}
- (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