简体   繁体   English

Objective-C表推视图

[英]objective-c Table Push view

I am currently working on a push table View Controller I have a navigation controller on my table view. 我目前正在使用推式表View Controller,在表视图上有一个导航控制器。 I Need To get it to load a push view for my categories: Movies, Tv Shows, ect . 我需要获取它来加载我的类别的推送视图:电影,电视节目等。 I made a second Table-View controller to load the table Push View I wasn't sure what i needed to do to accomplish this?!... This is my code for the second controller I used arrays to load the items; 我制作了第二个Table-View控制器来加载表Push View,我不确定要完成此操作需要做什么吗?!...这是我使用数组来加载项目的第二个控制器的代码;

 #import "itemViewController.h" @interface itemViewController () <UIAlertViewDelegate> @property (nonatomic) NSMutableArray *items; @end @implementation itemViewController //Buttons and Cells View. - (void)viewDidLoad { [super viewDidLoad]; //Edit/Done Button. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStylePlain target:self action:@selector(toggleEditing:)]; //Add Item. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(addNewItem:)]; //The Stuff Below I need to turn into a switch statement to load the right one how can I accomplish this? //movie self.items = @[@{@"name" : @"Avatar"},@{@"name" : @"SharkNado"},@{@"name" : @"Kung Fu Panda"}].mutableCopy; self.navigationItem.title = @"Movies"; /* //Tv Shows self.items = @[@{@"name" : @"Avatar the last Airbender"},@{@"name" : @"Reguluar Show"},@{@"name" : @""}].mutableCopy; self.navigationItem.title = @"TV Shows"; //Restaurants self.items = @[@{@"name" : @""},@{@"name" : @""},@{@"name" : @""}].mutableCopy; self.navigationItem.title = @"Restaurants"; //Concert Venues self.items = @[@{@"name" : @""},@{@"name" : @""},@{@"name" : @""}].mutableCopy; self.navigationItem.title = @"Concert Venues"; //Video Games self.items = @[@{@"name" : @""},@{@"name" : @""},@{@"name" : @""}].mutableCopy; self.navigationItem.title = @"Video Games"; //Foods self.items = @[@{@"name" : @""},@{@"name" : @""},@{@"name" : @""}].mutableCopy; self.navigationItem.title = @"Food"; //Recipes self.items = @[@{@"name" : @"Chocolate Chip Cookies"},@{@"name" : @""},@{@"name" : @""}].mutableCopy; self.navigationItem.title = @"Recipes"; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } */ } //Editing For Delete. #pragma mark - Editing - (void)toggleEditing:(UIBarButtonItem *)sender { [self.tableView setEditing:!self.tableView.editing animated:YES]; if (self.tableView.editing) { sender.title = @"Done"; sender.style = UIBarButtonItemStyleDone; } else { sender.title = @"Edit"; sender.style = UIBarButtonItemStylePlain; } } //Adding the Items. #pragma mark - adding items - (void) addNewItem:(UIBarButtonItem *)sender { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"New Movie" message:@"Please Enter the Title of the New Movie" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add Item", nil]; alertView.alertViewStyle = UIAlertViewStylePlainTextInput; [alertView show]; } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex != alertView.cancelButtonIndex) { UITextField *itemNameField = [alertView textFieldAtIndex:0]; NSString *itemName = itemNameField.text; NSDictionary *item = @{@"name" : itemName,}; [self.items addObject:item]; [self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForItem:self.items.count - 1 inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic]; } } //Table View Settings. #pragma mark - Table view datasource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.items.count; } //Cell Accessory onclick CheckMark. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Item"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSDictionary *item = self.items[indexPath.row]; cell.textLabel.text = item[@"name"]; if ([item[@"completed"] boolValue]) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } else { cell.accessoryType = UITableViewCellAccessoryNone; } return cell; } //table View Delegate. #pragma mark - Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSMutableDictionary *item = [self.items[indexPath.row] mutableCopy]; BOOL completed = [item[@"completed"] boolValue]; item[@"completed" ] = @(!completed); self.items[indexPath.row] = item; UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; cell.accessoryType = ([item[@"completed"] boolValue]) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone; [tableView deselectRowAtIndexPath:indexPath animated:YES]; } //editing -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewCellEditingStyleDelete; } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } //Removes Item //- (void)tableview:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { // if (editingStyle == UITableViewCellEditingStyleDelete) { // [self removeItemAtIndexPath:indexPath]; // [tableView deleteRowAtIndexPaths;@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; // } //} @end 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM