Mikhail Kuznetsov avatar Mikhail Kuznetsov committed dff12a1

missed file;

Comments (0)

Files changed (2)

MyShows/Controllers/ShowsListTableViewController.h

+//
+//  ShowsListTableViewController.h
+//  MyShows
+//
+//  Created by Mikhail Kuznetsov on 22.10.11.
+//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import "MyShowsApi.h"
+
+@interface ShowsListTableViewController : UITableViewController <ApiDelegate> {
+    MyShowsApi *api;
+    NSMutableArray *shows;
+    
+    IBOutlet UITableView *showsTable;
+}
+
+@end

MyShows/Controllers/ShowsListTableViewController.m

+//
+//  ShowsListTableViewController.m
+//  MyShows
+//
+//  Created by Mikhail Kuznetsov on 22.10.11.
+//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "ShowsListTableViewController.h"
+
+
+@implementation ShowsListTableViewController
+
+- (id)initWithStyle:(UITableViewStyle)style
+{
+    self = [super initWithStyle:style];
+    if (self) {
+        // Custom initialization
+    }
+    return self;
+}
+
+- (void)didRequestSucceed:(NSDictionary *)data {
+    NSLog(@"Returned to view after successful request");
+    int status = [(NSNumber *)[data objectForKey:@"status"] intValue];
+    
+    if (status == 200 ) {
+        id key;
+        
+        NSDictionary *loaded_shows = [[data objectForKey:@"data"] copy];
+                
+        NSEnumerator *enumerator = [loaded_shows keyEnumerator];
+        
+        shows = [[NSMutableArray alloc] init];
+        
+        while (key = [enumerator nextObject]) {            
+            if ([[loaded_shows objectForKey:key] isKindOfClass:[NSDictionary class]]){
+                [shows addObject:[[loaded_shows objectForKey:key] copy]];
+            }
+        }
+        NSLog(@"Data stored in array %d, %@", [shows count], shows);
+        
+        [showsTable reloadData];
+    }
+    else {
+        UIAlertView *alert = [[UIAlertView alloc]
+                              initWithTitle:@""
+                              message:nil
+                              delegate:nil
+                              cancelButtonTitle:@"OK"
+                              otherButtonTitles:nil];
+        if (status == 401) {
+            [alert setTitle:@"Log in, please"];
+        }
+        [alert show];
+    }
+}
+
+- (void)didReceiveMemoryWarning
+{
+    // Releases the view if it doesn't have a superview.
+    [super didReceiveMemoryWarning];
+    
+    // Release any cached data, images, etc that aren't in use.
+}
+
+#pragma mark - View lifecycle
+
+- (void)viewDidLoad
+{
+    [super viewDidLoad];
+    
+    api = [[MyShowsApi alloc] init];
+    [api setResponder:self];
+
+    // Uncomment the following line to preserve selection between presentations.
+    // self.clearsSelectionOnViewWillAppear = NO;
+ 
+    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
+    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
+}
+
+- (void)viewDidUnload
+{
+    [super viewDidUnload];
+    // Release any retained subviews of the main view.
+    // e.g. self.myOutlet = nil;
+}
+
+- (void)viewWillAppear:(BOOL)animated
+{
+    [super viewWillAppear:animated];
+}
+
+- (void)viewDidAppear:(BOOL)animated
+{
+    [super viewDidAppear:animated];
+    
+    [api sendRequest:@"shows" queryParams:nil];
+}
+
+- (void)viewWillDisappear:(BOOL)animated
+{
+    [super viewWillDisappear:animated];
+}
+
+- (void)viewDidDisappear:(BOOL)animated
+{
+    [super viewDidDisappear:animated];
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+    // Return YES for supported orientations
+    return (interfaceOrientation == UIInterfaceOrientationPortrait);
+}
+
+#pragma mark - Table view data source
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+    // Return the number of sections.
+    return 1;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+    // Return the number of rows in the section.
+    NSLog(@"Rows in section %d", [shows count]);
+    return [shows count];
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    static NSString *CellIdentifier = @"Cell";
+    
+    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
+    if (cell == nil) {
+        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
+    }
+    
+    // Configure the cell...
+    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
+         
+    NSString *ruTitle = [(NSDictionary *)[shows objectAtIndex:[indexPath row]] objectForKey:@"ruTitle"];
+         
+    if (ruTitle != (id)[NSNull null] && ruTitle != nil && ruTitle.length != 0) {
+        cell.detailTextLabel.text = ruTitle;
+    }
+    
+    cell.textLabel.text = [(NSDictionary *)[shows objectAtIndex:[indexPath row]] objectForKey:@"title"];
+    
+    //UIImage *showImage = [UIImage 
+    
+    return cell;
+}
+
+- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
+    if (indexPath.row == 0 || indexPath.row % 2 == 0) {
+        cell.backgroundColor = [UIColor colorWithWhite:0.7 alpha:0.1];
+    }
+}
+
+/*
+// Override to support conditional editing of the table view.
+- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    // Return NO if you do not want the specified item to be editable.
+    return YES;
+}
+*/
+
+/*
+// Override to support editing the table view.
+- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    if (editingStyle == UITableViewCellEditingStyleDelete) {
+        // Delete the row from the data source
+        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
+    }   
+    else if (editingStyle == UITableViewCellEditingStyleInsert) {
+        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
+    }   
+}
+*/
+
+/*
+// Override to support rearranging the table view.
+- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
+{
+}
+*/
+
+/*
+// Override to support conditional rearranging of the table view.
+- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    // Return NO if you do not want the item to be re-orderable.
+    return YES;
+}
+*/
+
+#pragma mark - Table view delegate
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    // Navigation logic may go here. Create and push another view controller.
+    /*
+     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
+     // ...
+     // Pass the selected object to the new view controller.
+     [self.navigationController pushViewController:detailViewController animated:YES];
+     */
+}
+
+@end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.