Created
May 17, 2012 04:02
-
-
Save georgejecook/2716202 to your computer and use it in GitHub Desktop.
wtf is wrong with this tableview? - didSelectIndexPath is returning wrong values - and first touch selects the row, but didSelectIndexPath is not called
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface OVChannelViewController : UIViewController <OVChannelManagerDelegate, UITableViewDataSource, UITableViewDelegate> | |
@property (strong, nonatomic) NSArray *channels; | |
@property (strong, nonatomic) UITableView *tableView; | |
@end | |
// | |
// OVChannelViewController.m | |
// OnVidi | |
// | |
// Created by George Cook on 21/02/2012. | |
// Copyright (c) 2012 __MyCompanyName__. All rights reserved. | |
// | |
#import "OVChannelViewController.h" | |
#import "OVResultList.h" | |
#import "OVChannel.h" | |
#import "OVSpringboardViewController.h" | |
#import "OVChannelVideoViewController.h" | |
#import "OVChannelCEll.h" | |
@interface OVChannelViewController () | |
- (void)initializeChannels; | |
@end | |
@implementation OVChannelViewController { | |
id _selectedChannel; | |
} | |
@synthesize channels = _channels; | |
@synthesize tableView = _tableView; | |
#pragma mark - | |
#pragma mark lifecycle | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds]; | |
self.tableView.delegate = self; | |
self.tableView.dataSource = self; | |
//self.tableView.backgroundColor = [UIColor clearColor]; | |
[self.view addSubview:self.tableView]; | |
// self.tableView.opaque = NO; | |
//self.tableView.scrollEnabled = NO; | |
// [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine]; | |
// [self.tableView setSeparatorColor:[UIColor lightGrayColor]]; | |
// | |
self.navigationItem.title = @"Categories"; | |
if (![OVChannelManager shared].isInitialized) { | |
[OVChannelManager shared].delegate = self; | |
//self.tableView.hidden = YES; | |
[[OVChannelManager shared] initializeChannels]; | |
} else { | |
[self initializeChannels]; | |
} | |
} | |
- (void)viewDidUnload { | |
[self setTableView:nil]; | |
[super viewDidUnload]; | |
if ([OVChannelManager shared].delegate == self) { | |
[OVChannelManager shared].delegate = nil; | |
} | |
self.channels = nil; | |
} | |
- (void)viewWillAppear:(BOOL)animated { | |
[super viewWillAppear:YES]; | |
self.navigationItem.leftBarButtonItem = [TTSpringBoardViewController sharedInstance].homeNavigationButton; | |
} | |
- (void)viewWillDisappear:(BOOL)animated { | |
[super viewDidDisappear:animated]; | |
} | |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { | |
return (interfaceOrientation == UIInterfaceOrientationPortrait); | |
} | |
#pragma mark - Table view data source | |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { | |
return 1; | |
} | |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | |
return _channels.count; | |
} | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
int row = indexPath.row; | |
OVChannel *channel = [_channels objectAtIndex:row]; | |
NSLog(@"MADE CELL %d - channel is %@",row, channel); | |
//OVChannelCell *cell = [[OVChannelCell alloc] initWithChannel:channel]; | |
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; | |
cell.textLabel.text = channel.name; | |
return cell; | |
} | |
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { | |
return 77; | |
} | |
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { | |
int row = indexPath.row; | |
_selectedChannel = [_channels objectAtIndex: row]; | |
NSLog(@"selected ip %@ - channel is %@",indexPath , _selectedChannel); | |
[self performSegueWithIdentifier:@"Videos" sender:self]; | |
} | |
#pragma mark - Segue | |
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { | |
if ([segue.destinationViewController isKindOfClass:[OVChannelVideoViewController class]]) { | |
((OVChannelVideoViewController *) segue.destinationViewController).channel = _selectedChannel; | |
} | |
} | |
#pragma mark OVChannelManager impl | |
- (void)channelManager:(OVChannelManager *)channelManager didRetrieveChannels:(NSArray *)channels { | |
//we are good to go! - show the table, hide the spinner. | |
[self initializeChannels]; | |
self.tableView.hidden = NO; | |
[self.tableView reloadData]; | |
} | |
- (void)channelManagerFailedToRetrieveChannels:(OVChannelManager *)channelManager { | |
//display alert to say we are not connected to the internets | |
} | |
#pragma mark private impl | |
- (void)initializeChannels { | |
// NSMutableArray *allChannels = [NSMutableArray arrayWithArray:[OVChannelManager shared].channels]; | |
// [allChannels insertObject:[OVChannelManager shared].allChannel atIndex:0]; | |
self.channels = [OVChannelManager shared].channels; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment