簡體   English   中英

Objective-C表推視圖

[英]objective-c Table Push view

我目前正在使用推式表View Controller,在表視圖上有一個導航控制器。 我需要獲取它來加載我的類別的推送視圖:電影,電視節目等。 我制作了第二個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