文档库 最新最全的文档下载
当前位置:文档库 › TableView

TableView

TableView
TableView

//

// TableViewViewController.h

// TableView

//

// Created by student on 14-5-21.

// Copyright (c) 2014年. All rights reserved.

//

#import

@interface TableView ViewController : UIV iewController

@end

//

// TableViewViewController.m

// TableView

//

// Created by student on 14-5-21.

// Copyright (c) 2014年. All rights reserved.

//

#import "TableViewViewController.h"

#import "HistoryTableViewController.h"

@interface TableView ViewController () @property (weak, nonatomic) IBOutlet UITextField *num1; @property (weak, nonatomic) IBOutlet UITextField *num2; @property (weak, nonatomic) IBOutlet UITextField *num3; @property (nonatomic,strong) NSMutableArray *history;

@end

@implementation TableView ViewController

- (NSMutableArray *)history{

if (!_history) {

_history = [[NSMutableArray alloc] init];

}

return _history;

}

- (void)viewDidLoad

{

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

}

- (IBAction)add:(id)sender {

self.num3.text = [NSString stringWithFormat:@"%d",self.num1.text.intV alue+self.num2.text.intV alue];

[self.history addObject:[NSString stringWithFormat:

@"%@ add %@ =%@",self.num1.text,self.num2.text,self.num3.text]];

}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{

[textField resignFirstResponder];

return YES;

}

- (void)didReceiveMemoryWarning

{

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

if ([segue.destinationViewController isKindOfClass:[HistoryTableViewController class]]) { HistoryTableViewController *htvc = segue.destinationViewController;

htvc.History = self.history;

}

}

@end

//

// HistoryTableViewController.h

// TableView

//

// Created by student on 14-5-21.

// Copyright (c) 2014年. All rights reserved.

#import

@interface HistoryTableViewController : UITableViewController

@property (nonatomic, strong) NSMutableArray *History;

@end

//

// HistoryTableViewController.m

// TableView

//

// Created by student on 14-5-21.

// Copyright (c) 2014年. All rights reserved.

//

#import "HistoryTableViewController.h"

@interface HistoryTableViewController ()

@end

@implementation HistoryTableViewController

- (id)initWithStyle:(UITableViewStyle)style

{

self = [super initWithStyle:style];

if (self) {

// Custom initialization

}

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;

}

- (void)didReceiveMemoryWarning

{

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableV iew

{

// Return the number of sections.

return 2;

}

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

// Return the number of rows in the section.

return [self.History count];

}

- (UITableV iewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

static NSString *CellIdentifier = @"myCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

cell.textLabel.text = self.History[indexPath.row];

// Configure the cell...

return cell;

}

/*

// 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 *)tableV iew 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 story board-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

//

// TableViewAppDelegate.h

// TableView

//

// Created by student on 14-5-21.

// Copyright (c) 2014年. All rights reserved.

//

#import

@interface TableView AppDelegate : UIResponder

@property (strong, nonatomic) UIWindow *window;

@end

//

// TableViewAppDelegate.m

// TableView

//

// Created by student on 14-5-21.

// Copyright (c) 2014年. All rights reserved.

//

#import "TableViewAppDelegate.h"

@implementation TableView AppDelegate

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

{

// Override point for customization after application launch.

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

//

// main.m

// TableView

//

// Created by student on 14-5-21.

// Copyright (c) 2014年. All rights reserved.

//

#import

#import "TableViewAppDelegate.h"

int main(int argc, char * argv[])

{

@autoreleasepool {

return UIApplicationMain(argc, argv, nil, NSStringFromClass([TableViewAppDelegate class]));

}

}

//

// TableViewTests.m

// TableViewTests

//

// Created by student on 14-5-21.

// Copyright (c) 2014年. All rights reserved.

//

#import

@interface TableViewTests : XCTestCase

@end

@implementation TableViewTests

- (void)setUp

[super setUp];

// Put setup code here. This method is called before the invocation of each test method in the class.

}

- (void)tearDown

{

// Put teardown code here. This method is called after the invocation of each test method in the class.

[super tearDown];

}

- (void)testExample

{

XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__);

}

@end

相关文档