-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPAGroupSelectionViewController.m
More file actions
106 lines (83 loc) · 3.28 KB
/
Copy pathPAGroupSelectionViewController.m
File metadata and controls
106 lines (83 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
// PAGroupSelectionViewController.m
// prayApp
//
// Created by Jeff Wang on 12/27/13.
// Copyright (c) 2013 Jeff Wang. All rights reserved.
//
#import "PAGroupSelectionViewController.h"
@interface PAGroupSelectionViewController ()
@end
@implementation PAGroupSelectionViewController
@synthesize prayerGroupList, delegate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (id)init{
self = [super init];
if (self){
prayerGroupTableView = [[UITableView alloc] init];
prayerGroupTableView.delegate = self;
prayerGroupTableView.dataSource = self;
prayerGroupList = [[NSMutableArray alloc] init];
selectedGroupIndex = 0;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
prayerGroupTableView.frame = self.view.bounds;
[self.view addSubview:prayerGroupTableView];
self.title = @"Prayer Groups";
UIBarButtonItem* cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelSelection:)];
UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(doneSelection:)];
self.navigationItem.leftBarButtonItem = cancelButton;
self.navigationItem.rightBarButtonItem = doneButton;
}
- (void)cancelSelection:(id)sender{
[delegate groupSelectionDidCancel];
[self dismissViewControllerAnimated:YES completion:^{
}];
}
- (void)doneSelection:(id)sender{
[delegate groupSelectionDidSelect:[prayerGroupList objectAtIndex:selectedGroupIndex]];
[self dismissViewControllerAnimated:YES completion:^{
}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
cell.textLabel.text = [prayerGroupList objectAtIndex:indexPath.row];
if (indexPath.row == selectedGroupIndex)
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
else
[cell setAccessoryType:UITableViewCellAccessoryNone];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// remove the selected background color
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];
[[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:selectedGroupIndex inSection:0]] setAccessoryType:UITableViewCellAccessoryNone];
selectedGroupIndex = indexPath.row;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 44;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [prayerGroupList count];
}
@end