Moving error alert logic from models to controllers

This commit is contained in:
Mattt Thompson 2012-08-11 11:16:55 -04:00
parent fbc4ec5dbd
commit 3d6fcc35c9
5 changed files with 15 additions and 14 deletions

View file

@ -189,8 +189,8 @@
children = ( children = (
F8DA09E31396AC040057D0CC /* main.m */, F8DA09E31396AC040057D0CC /* main.m */,
F8129C3815910830009BFE23 /* Prefix.pch */, F8129C3815910830009BFE23 /* Prefix.pch */,
F8129C7215910C37009BFE23 /* AppDelegate.m */,
F8129C7315910C37009BFE23 /* AppDelegate.h */, F8129C7315910C37009BFE23 /* AppDelegate.h */,
F8129C7215910C37009BFE23 /* AppDelegate.m */,
F8E4696C1395739D00DB05C8 /* iOS-Info.plist */, F8E4696C1395739D00DB05C8 /* iOS-Info.plist */,
); );
name = "Supporting Files"; name = "Supporting Files";

View file

@ -71,7 +71,11 @@ didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
[self.window makeKeyAndOrderFront:self]; [self.window makeKeyAndOrderFront:self];
[Tweet publicTimelineTweetsWithBlock:^(NSArray *tweets) { [Tweet publicTimelineTweetsWithBlock:^(NSArray *tweets, NSError *error) {
if (error) {
[[NSAlert alertWithMessageText:NSLocalizedString(@"Error", nil) defaultButton:NSLocalizedString(@"OK", nil) alternateButton:nil otherButton:nil informativeTextWithFormat:@"%@",[error localizedDescription]] runModal];
}
self.tweetsArrayController.content = tweets; self.tweetsArrayController.content = tweets;
}]; }];

View file

@ -41,8 +41,10 @@
[_activityIndicatorView startAnimating]; [_activityIndicatorView startAnimating];
self.navigationItem.rightBarButtonItem.enabled = NO; self.navigationItem.rightBarButtonItem.enabled = NO;
[Tweet publicTimelineTweetsWithBlock:^(NSArray *tweets) { [Tweet publicTimelineTweetsWithBlock:^(NSArray *tweets, NSError *error) {
if (tweets) { if (error) {
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", nil) message:[error localizedDescription] delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"OK", nil), nil] show];
} else {
_tweets = tweets; _tweets = tweets;
[self.tableView reloadData]; [self.tableView reloadData];
} }

View file

@ -33,6 +33,6 @@
- (id)initWithAttributes:(NSDictionary *)attributes; - (id)initWithAttributes:(NSDictionary *)attributes;
+ (void)publicTimelineTweetsWithBlock:(void (^)(NSArray *tweets))block; + (void)publicTimelineTweetsWithBlock:(void (^)(NSArray *tweets, NSError *error))block;
@end @end

View file

@ -52,7 +52,7 @@
#pragma mark - #pragma mark -
+ (void)publicTimelineTweetsWithBlock:(void (^)(NSArray *tweets))block { + (void)publicTimelineTweetsWithBlock:(void (^)(NSArray *tweets, NSError *error))block {
[[AFTwitterAPIClient sharedClient] getPath:@"statuses/public_timeline.json" parameters:[NSDictionary dictionaryWithObject:@"false" forKey:@"include_entities"] success:^(AFHTTPRequestOperation *operation, id JSON) { [[AFTwitterAPIClient sharedClient] getPath:@"statuses/public_timeline.json" parameters:[NSDictionary dictionaryWithObject:@"false" forKey:@"include_entities"] success:^(AFHTTPRequestOperation *operation, id JSON) {
NSMutableArray *mutableTweets = [NSMutableArray arrayWithCapacity:[JSON count]]; NSMutableArray *mutableTweets = [NSMutableArray arrayWithCapacity:[JSON count]];
for (NSDictionary *attributes in JSON) { for (NSDictionary *attributes in JSON) {
@ -61,16 +61,11 @@
} }
if (block) { if (block) {
block([NSArray arrayWithArray:mutableTweets]); block([NSArray arrayWithArray:mutableTweets], nil);
} }
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
#if __IPHONE_OS_VERSION_MIN_REQUIRED
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", nil) message:[error localizedDescription] delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"OK", nil), nil] show];
#else
[[NSAlert alertWithMessageText:NSLocalizedString(@"Error", nil) defaultButton:NSLocalizedString(@"OK", nil) alternateButton:nil otherButton:nil informativeTextWithFormat:@"%@",[error localizedDescription]] runModal];
#endif
if (block) { if (block) {
block(nil); block([NSArray array], error);
} }
}]; }];
} }