您的位置:首页 > 产品设计 > UI/UE

UI15_UITableViewController

2015-08-25 08:48 274 查看
//
//  AppDelegate.h
//  UI15_UITableViewController
//
//  Created by dllo on 15/8/18.
//  Copyright (c) 2015年 flg. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
//
//  AppDelegate.m
//  UI15_UITableViewController
//
//  Created by dllo on 15/8/18.
//  Copyright (c) 2015年 flg. All rights reserved.
//

#import "AppDelegate.h"
#import "MyTableViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate
- (void)dealloc{
[_window release];
[super dealloc];

}

- (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];
[_window release];
MyTableViewController *my=[[MyTableViewController alloc] init];
UINavigationController *naVC=[[UINavigationController alloc] initWithRootViewController:my];
self.window.rootViewController=naVC;
[naVC release];
[my release];

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:.
}

@end


//
//  MyTableViewController.h
//  UI15_UITableViewController
//
//  Created by dllo on 15/8/18.
//  Copyright (c) 2015年 flg. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface MyTableViewController : UITableViewController

@end


//
//  MyTableViewController.m
//  UI15_UITableViewController
//
//  Created by dllo on 15/8/18.
//  Copyright (c) 2015年 flg. All rights reserved.
//

#import "MyTableViewController.h"

@interface MyTableViewController ()
@property(nonatomic,retain)NSMutableArray *arr;
@property(nonatomic,retain)UIRefreshControl *refresh;
@property(nonatomic,retain)UITableViewCell *cell;
@end

@implementation MyTableViewController
- (void)dealloc{
[_arr release];
[_refresh release];
[super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.arr= [NSMutableArray arrayWithObjects:@"宋江", @"卢俊义", @"吴用", @"公孙胜", @"关胜", @"林冲", @"秦明" ,@"呼延灼" , @"花容",@"柴进", @"李应", @"朱仝",@"鲁智深",@"武松",nil];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];

// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
//系统默认的刷新 下拉
self.refresh=[[UIRefreshControl alloc] init];
self.refresh.attributedTitle=[[NSAttributedString alloc] initWithString:@"正在加载..."];
[self.view addSubview:self.refresh];
[self.refresh addTarget:self action:@selector(refreshAction:) forControlEvents:UIControlEventValueChanged];

}
- (void)refreshAction:(UIRefreshControl *)control{
[control endRefreshing];
[self.arr addObject:@"安逸臣"];
[self.tableView reloadData];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
// Return the number of rows in the section.
return self.arr.count;
}

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

static NSString *reuse=@"reuse";
self.cell = [tableView dequeueReusableCellWithIdentifier:reuse];

if (!self.cell) {
self.cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse] autorelease];
}
self.cell.textLabel.text=self.arr[indexPath.row];

return self.cell;
}

#pragma mark 设置是否允许添加菜单
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
#pragma mark 设置是否允许tableView的cell添加事件
-(BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{
return YES;
}
#pragma mark  当我们点击菜单上的按钮会出现的方法
-(void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{
if (action==@selector(copy:)) {
NSLog(@"拷贝");
}

}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: