summaryrefslogtreecommitdiffstats
path: root/Classes/SourcesEditViewController.m
diff options
context:
space:
mode:
authormatt handler <matt.handler@gmail.com>2011-04-25 02:21:36 -0400
committermatt handler <matt.handler@gmail.com>2011-04-25 02:21:36 -0400
commitab0c357216564967ccbb900923ead3830a13752b (patch)
tree1b3aa223efb245d47b9c6ba785d2db4e911fd62a /Classes/SourcesEditViewController.m
parent0c7a7586d3c2ab22adb15f032b0a69c962aaeeaf (diff)
downloadpiccast-app-ab0c357216564967ccbb900923ead3830a13752b.tar.gz
piccast-app-ab0c357216564967ccbb900923ead3830a13752b.zip
added json stuff, sources are loading but not connected to any sensical database or nothing... coming together. next hard bit is going to be the animation when things update
Diffstat (limited to 'Classes/SourcesEditViewController.m')
-rw-r--r--Classes/SourcesEditViewController.m135
1 files changed, 107 insertions, 28 deletions
diff --git a/Classes/SourcesEditViewController.m b/Classes/SourcesEditViewController.m
index d0ca382..93007a9 100644
--- a/Classes/SourcesEditViewController.m
+++ b/Classes/SourcesEditViewController.m
@@ -8,7 +8,8 @@
#import "SourcesEditViewController.h"
#import "SourcesEditViewCell.h"
-
+#import "CJSONDeserializer.h"
+#import "PicCastAppDelegate.h"
@implementation SourcesEditViewController
@@ -21,13 +22,29 @@
- (void)viewDidLoad {
[super viewDidLoad];
- self.tableView.rowHeight = 100;
+ self.tableView.rowHeight = 44;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
//NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
- self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
+ self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
+
+ sectionDictionary = [[[SectionDictionary alloc] init] retain];
+
+ _receivedData = [[NSMutableData data] retain];
+ NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://piccast.memeschemes.com/json/feeds/"]
+ cachePolicy:NSURLRequestUseProtocolCachePolicy
+ timeoutInterval:30.0];
+
+ if ([NSURLConnection connectionWithRequest:theRequest delegate:self]) {
+ [_receivedData setLength:0];
+ } else {
+ //[MBProgressHUD hideHUDForView:self.view animated:YES];
+ [PicCastAppDelegate prompt:@"Error" withMessage:@"No internet connection" andButtonTitle:@"shucks" withDelegate:self];
+ }
+
+ //[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:YES] forKey:@"haveSearched"];
}
- (IBAction)done:(id)sender {
@@ -67,50 +84,110 @@
}
*/
+#pragma mark -
+#pragma mark url response
+
+- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
+ [_receivedData setLength:0];
+}
+
+- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
+ [_receivedData appendData:data];
+}
+
+- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
+
+ //[_receivedData release];
+
+ //[MBProgressHUD hideHUDForView:self.view animated:YES];
+ [PicCastAppDelegate prompt:@"Error" withMessage:[error localizedDescription] andButtonTitle:@"Aww man..." withDelegate:self];
+ //[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
+
+}
+
+- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
+// NSString *json = [[NSString alloc] initWithData:_receivedData encoding:NSUTF8StringEncoding];
+// [_tableData removeAllObjects];
+// [_tableData addObjectsFromArray:[[json JSONValue] objectForKey:@"results"]];
+// [json release];
+//
+// if ([_tableData count] > 0) {
+// [tableView reloadData];
+// [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
+// self.tableView.allowsSelection = YES;
+// self.tableView.scrollEnabled = YES;
+// }
+
+ //[MBProgressHUD hideHUDForView:self.view animated:YES];
+
+ //[_receivedData release];
+
+ NSError *theError = nil;
+ id array = [[CJSONDeserializer deserializer] deserialize:(NSData *)_receivedData error:&theError];
+ //NSLog(@"class: %@", [array class]);
+ for (NSDictionary *obj in array) {
+ [sectionDictionary appendObject:obj forKey:@"Potpourri"];
+ }
+
+ [tableView reloadData];
+}
#pragma mark -
#pragma mark Table view data source
-//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
-// // Return the number of sections.
-// return <#number of sections#>;
-//}
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
+ // Return the number of sections.
+ return [sectionDictionary count];
+}
//
//
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
- return 10;
+ return [[sectionDictionary objectForIndex:section] count];
+}
+
+- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
+ return [sectionDictionary keyForIndex:section];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *CellIdentifier = @"SourcesEditCell";
+ static NSString *CellIdentifier = @"cell";
- SourcesEditViewCell *cell = (SourcesEditViewCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
+ UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
- NSArray *tmpCell = [[NSBundle mainBundle] loadNibNamed:@"TopicTableViewCell" owner:self options:nil];
-
- for (id currentObj in tmpCell) {
- if ([currentObj isKindOfClass:[TopicTableViewCell class]]) {
- cell = (SourcesEditViewCell *)currentObj;
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
-
- UISwitch *mySwitch = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
- [cell addSubview:mySwitch];
- cell.accessoryView = mySwitch;
-
- //cell.accessoryView = cell.switcher;
- break;
- }
- }
- //cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
- }
+// NSArray *tmpCell = [[NSBundle mainBundle] loadNibNamed:@"TopicTableViewCell" owner:self options:nil];
+//
+// for (id currentObj in tmpCell) {
+// if ([currentObj isKindOfClass:[TopicTableViewCell class]]) {
+// cell = (TopicTableViewCell *)currentObj;
+// [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
+//
+// UISwitch *mySwitch = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
+// [cell addSubview:mySwitch];
+// cell.accessoryView = mySwitch;
+//
+// //cell.accessoryView = cell.switcher;
+// break;
+// }
+// }
+ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
+ }
// Configure the cell...
-
+ [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
+
+
+ NSDictionary *obj = [[sectionDictionary objectForIndex:indexPath.section] objectAtIndex:indexPath.row];
+ [cell setText:[[obj objectForKey:@"fields"] objectForKey:@"title"]];
+
+ UISwitch *mySwitch = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
+ [cell addSubview:mySwitch];
+ cell.accessoryView = mySwitch;
+
return cell;
}
@@ -187,6 +264,8 @@
- (void)dealloc {
+ [sectionDictionary release];
+ [_receivedData release];
[super dealloc];
}