Skip to content

Commit 7dbc361

Browse files
added methods to dynamically change/creat credits
1 parent 6f26c79 commit 7dbc361

File tree

5 files changed

+106
-26
lines changed

5 files changed

+106
-26
lines changed

Classes/MDACClasses.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@
3737
#import "MDACListCredit.h"
3838
#import "MDACTextCredit.h"
3939
#import "MDACImageCredit.h"
40-
#import "MDACIconCredit.h"
40+
#import "MDACIconCredit.h"
41+
#import "MDACWebViewController.h"

Classes/MDWebViewController.h renamed to Classes/MDACWebViewController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// MDAboutController.h
2+
// MDACWebViewController.h
33
// MDAboutController
44
//
55
// Created by Doron Katz 5/23/11.
@@ -32,7 +32,7 @@
3232
#import <UIKit/UIKit.h>
3333

3434

35-
@interface MDWebViewController : UIViewController <UIWebViewDelegate, UIAlertViewDelegate> {
35+
@interface MDACWebViewController : UIViewController <UIWebViewDelegate, UIAlertViewDelegate> {
3636
NSURL* webURL;
3737
UIActivityIndicatorView* activity;
3838
UIWebView* webV;

Classes/MDWebViewController.m renamed to Classes/MDACWebViewController.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// MDWebViewController.m
2+
// MDACWebViewController.m
33
// MDAboutController
44
//
55
// Created by Doron Katz 5/23/11.
@@ -29,10 +29,10 @@
2929
// automatically by the code that links back to this page :)
3030
//
3131

32-
#import "MDWebViewController.h"
32+
#import "MDACWebViewController.h"
3333

3434

35-
@implementation MDWebViewController
35+
@implementation MDACWebViewController
3636

3737
@synthesize webURL, activity, webV, alert;
3838

Classes/MDAboutController.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
//
3232

3333
#import <UIKit/UIKit.h>
34-
#import "MDWebViewController.h"
34+
@class MDACCredit;
3535

3636
@interface MDAboutController : UIViewController <UITableViewDataSource, UITableViewDelegate> {
3737
UIView *titleBar;
@@ -50,17 +50,27 @@
5050
BOOL hasSimpleBackground;
5151
}
5252

53-
- (void)generateCachedCells;
54-
- (void)generateCachedCellsIfNeeded;
53+
- (void)generateCachedCells; // internal
54+
- (void)generateCachedCellsIfNeeded; // internal
5555

56-
- (IBAction)dismiss:(id)sender;
56+
- (IBAction)dismiss:(id)sender; // hide if modal
5757

5858
@property (nonatomic, retain) UIView *titleBar;
5959

60-
@property (nonatomic) BOOL showsTitleBar;
60+
@property (nonatomic) BOOL showsTitleBar; // set to NO automatically when in navcontroller.
6161
- (void)setShowsTitleBar:(BOOL)yn animated:(BOOL)animated;
6262

6363
@property (nonatomic, retain) UIColor *backgroundColor;
64-
@property (nonatomic) BOOL hasSimpleBackground;
64+
@property (nonatomic) BOOL hasSimpleBackground; // set automatically to YES for non patterend background. Set to YES for better performance, at the cost of a patterned background looking weird.
65+
66+
@property (nonatomic, readonly) NSArray *credits; // for fast enumeration
67+
@property (nonatomic, readonly) NSUInteger creditCount;
68+
69+
- (void)addCredit:(MDACCredit *)aCredit;
70+
- (void)insertCredit:(MDACCredit *)aCredit atIndex:(NSUInteger)index;
71+
- (void)replaceCreditAtIndex:(NSUInteger)index withCredit:(MDACCredit *)aCredit;
72+
- (void)removeLastCredit;
73+
- (void)removeCredit:(MDACCredit *)aCredit;
74+
- (void)removeCreditAtIndex:(NSUInteger)index;
6575

6676
@end

Classes/MDAboutController.m

Lines changed: 83 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#import "MDACTextCredit.h"
3939
#import "MDACImageCredit.h"
4040
#import "MDACIconCredit.h"
41+
#import "MDACWebViewController.h"
4142

4243
#pragma mark Constants
4344

@@ -52,7 +53,7 @@
5253

5354
@implementation MDAboutController
5455

55-
@synthesize showsTitleBar, titleBar, backgroundColor, hasSimpleBackground;
56+
@synthesize showsTitleBar, titleBar, backgroundColor, hasSimpleBackground, credits;
5657

5758
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
5859
{
@@ -71,14 +72,17 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
7172
//self.navigationItem.title = [NSString stringWithFormat:@"About %@", appName];
7273
self.navigationItem.title = @"About";
7374

74-
if ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] && [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]) {
75+
NSString *bundleShortVersionString = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
76+
NSString *bundleVersionString = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
77+
78+
if (bundleShortVersionString && bundleVersionString) {
7579
versionString = [NSString stringWithFormat:@"Version %@ (%@)",
76-
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"],
77-
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]];
78-
} else if ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]) {
79-
versionString = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
80-
} else if ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]) {
81-
versionString = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
80+
bundleShortVersionString,
81+
bundleVersionString];
82+
} else if (bundleShortVersionString) {
83+
versionString = [NSString stringWithFormat:@"Version %@", bundleShortVersionString];
84+
} else if (bundleVersionString) {
85+
versionString = [NSString stringWithFormat:@"Version %@", bundleVersionString];
8286
}
8387

8488
UIImage *icon = nil;
@@ -124,7 +128,6 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
124128

125129
if (icon) {
126130
UIImage *maskImage = [UIImage imageNamed:@"MDACIconMask.png"];
127-
//icon = maskImage;
128131
icon = [icon maskedImageWithMask:maskImage];
129132
}
130133

@@ -149,8 +152,7 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
149152
[creditsFile release];
150153
}
151154

152-
//TOFIX: Do we need this? People might not want to have this in their app, but we could find another way of adding credits? Perhaps
153-
// as a Credit item in the section table?
155+
// To remove (:sadface:) the following credit, call [aboutController removeLastCredit]; after initializing your controller.
154156

155157
[credits addObject:[MDACTextCredit textCreditWithText:@"About screen powered by MDAboutViewController, available free on GitHub!"
156158
font:[UIFont boldSystemFontOfSize:11]
@@ -192,7 +194,7 @@ - (void)didReceiveMemoryWarning
192194

193195

194196

195-
#pragma mark View lifecycle
197+
#pragma mark - View lifecycle
196198

197199
- (void)generateCachedCells
198200
{
@@ -564,7 +566,7 @@ - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath
564566
} else {
565567
NSURL *url = [(MDACListCredit *)credit itemAtIndex:index].link;
566568

567-
MDWebViewController *linkViewController = [[MDWebViewController alloc] initWithURL:url];
569+
MDACWebViewController *linkViewController = [[MDACWebViewController alloc] initWithURL:url];
568570
[[self navigationController] pushViewController:linkViewController animated:YES];
569571
[linkViewController release];
570572
}
@@ -577,7 +579,7 @@ - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath
577579
} else {
578580
NSURL *url =[(MDACTextCredit *)credit link];
579581

580-
MDWebViewController *linkViewController = [[MDWebViewController alloc] initWithURL:url];
582+
MDACWebViewController *linkViewController = [[MDACWebViewController alloc] initWithURL:url];
581583
[[self navigationController] pushViewController:linkViewController animated:YES];
582584
[linkViewController release];
583585
}
@@ -721,5 +723,72 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
721723
return YES;
722724
}
723725

726+
#pragma mark - Manipulating Credits
727+
728+
- (void)addCredit:(MDACCredit *)aCredit
729+
{
730+
[credits addObject:aCredit];
731+
732+
[cachedCellCredits release];
733+
cachedCellCredits = nil;
734+
735+
[tableView reloadData];
736+
}
737+
738+
- (void)insertCredit:(MDACCredit *)aCredit atIndex:(NSUInteger)index
739+
{
740+
[credits insertObject:aCredit atIndex:index];
741+
742+
[cachedCellCredits release];
743+
cachedCellCredits = nil;
744+
745+
[tableView reloadData];
746+
}
747+
748+
- (void)replaceCreditAtIndex:(NSUInteger)index withCredit:(MDACCredit *)aCredit
749+
{
750+
[credits replaceObjectAtIndex:index withObject:aCredit];
751+
752+
[cachedCellCredits release];
753+
cachedCellCredits = nil;
754+
755+
[tableView reloadData];
756+
}
757+
758+
- (void)removeLastCredit
759+
{
760+
[credits removeLastObject];
761+
762+
[cachedCellCredits release];
763+
cachedCellCredits = nil;
764+
765+
[tableView reloadData];
766+
}
767+
768+
- (void)removeCredit:(MDACCredit *)aCredit
769+
{
770+
[credits removeObject:aCredit];
771+
772+
[cachedCellCredits release];
773+
cachedCellCredits = nil;
774+
775+
[tableView reloadData];
776+
}
777+
778+
- (void)removeCreditAtIndex:(NSUInteger)index
779+
{
780+
[credits removeObjectAtIndex:index];
781+
782+
[cachedCellCredits release];
783+
cachedCellCredits = nil;
784+
785+
[tableView reloadData];
786+
}
787+
788+
- (NSUInteger)creditCount
789+
{
790+
return [credits count];
791+
}
792+
724793
@end
725794

0 commit comments

Comments
 (0)