objective-c Table 推送视图
objective-c Table Push view
我目前正在处理推送 table 视图控制器 我的 table 视图上有一个导航控制器。
我需要让它为我的类别加载推送视图:
电影、电视节目等。
我做了第二个 Table-View 控制器来加载 table 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
我目前正在处理推送 table 视图控制器 我的 table 视图上有一个导航控制器。 我需要让它为我的类别加载推送视图: 电影、电视节目等。 我做了第二个 Table-View 控制器来加载 table 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