-
Notifications
You must be signed in to change notification settings - Fork 32
/
MNAlertTableViewDataSourceEditable.m
61 lines (50 loc) · 2.04 KB
/
MNAlertTableViewDataSourceEditable.m
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
#import "MNAlertTableViewDataSourceEditable.h"
@implementation MNAlertTableViewDataSourceEditable
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MNTableViewCellClear *cell = (MNTableViewCellClear *) [tableView dequeueReusableCellWithIdentifier:@"notificationTableCell"];
if (cell == nil)
{
cell = [[[MNTableViewCellClear alloc] init] autorelease];
}
MNAlertData *dataObj;
if(type == kMNAlertTableViewDataSourceTypePending)
{
dataObj = [[_delegate getPendingAlerts] objectAtIndex:indexPath.row];
}
else if(type == kMNAlertTableViewDataSourceTypeArchived)
{
dataObj = [[_delegate getDismissedAlerts] objectAtIndex:indexPath.row];
}
else
{
dataObj = [[[MNAlertData alloc] initWithHeader:@"Null"
withText:@"Null"
andSenderAddress:nil
andType:kPushAlert
forBundleID:@"com.apple.calculator"
ofStatus:kNewAlertForeground]
autorelease];
}
cell.iconImageView.image = [_delegate iconForBundleID:dataObj.bundleID];
cell.headerLabel.text = dataObj.header;
cell.alertTextLabel.text = dataObj.text;
return cell;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
if (type == kMNAlertTableViewDataSourceTypePending)
{
// Dismiss the alert
[_delegate dismissedAlertAtIndex:indexPath.row];
}
// Delete row from tableview
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
// Reload data
[tableView reloadData];
[_delegate refreshAll];
}
}
@end