Xcode6 tableview点击+导航控制器不要转到collectionview

时间:2014-09-27 16:17:06

标签: ios objective-c uitableview uicollectionview xcode6

我的tableview中有一个问题,理论上当我连续点击它应该转到另一个视图时,但由于某些原因当我点击没有任何反应时,我不知道为什么我会尝试很多代码堆栈溢出和互联网,但我仍然有问题。哪里我做错了?

TABLEVIEWCONTROLLER.H

#import <UIKit/UIKit.h>
#import <AFNetworking.h>

@interface TableViewController : UITableViewController<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) NSArray *imageURLs;
@property (nonatomic, strong) AFHTTPRequestOperationManager *operationManager;
@property (nonatomic, assign) int verificaConnessione;

@property (assign, nonatomic) IBOutlet UILabel * blockLabel;
@property (assign, nonatomic) IBOutlet UILabel * notificationLabel;

@end

TABLEVIEWCONTROLLER.M

#import "TableViewController.h"
#import <AFNetworking.h>
#import "NSObject.h"
#import "Reachability.h"
#import "CollectionViewController.h"

@interface TableViewController ()

-(void)reachabilityChanged:(NSNotification*)note;

@end

@implementation TableViewController{
    NSArray *Titoli;
}

@synthesize blockLabel, notificationLabel;

- (NSArray *)imageURLs
{
    if (!_imageURLs)
    {
        NSArray *imageURLs = [[NSArray alloc]initWithObjects:@"http://i.imgur.com/RBGzfAT.jpg",   //accel world                                                          @"http://i.imgur.com/fDBv3aU.jpg",   //air gear                                                            
                      nil];

        _imageURLs = imageURLs;
    }

    return _imageURLs;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    // 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;


    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(reachabilityChanged:)
                                                 name:kReachabilityChangedNotification
                                               object:nil];

    Reachability * reach = [Reachability reachabilityWithHostname:@"www.google.com"];

    reach.reachableBlock = ^(Reachability * reachability)
    {
        dispatch_async(dispatch_get_main_queue(), ^{
            blockLabel.text = @"Block Says Reachable";
        });
    };

    reach.unreachableBlock = ^(Reachability * reachability)
    {
        dispatch_async(dispatch_get_main_queue(), ^{
            blockLabel.text = @"Block Says Unreachable";

            _verificaConnessione = 1;

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Nessuna connessione internet"
                                                            message:@"Per usare questa app devi aver abilitata la connessione internet"
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
            [alert show];
        });
    };

    [reach startNotifier];

    [self.tableView registerClass:[UITableViewCell class]
           forCellReuseIdentifier:@"TableViewCell"];

    Titoli = [[NSArray alloc]initWithObjects:@"Accel World",
                                              @"Air Gear",nil];


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)reachabilityChanged:(NSNotification*)note
{
    Reachability * reach = [note object];

    if([reach isReachable])
    {
        notificationLabel.text = @"Notification Says Reachable";
    }
    else
    {
        notificationLabel.text = @"Notification Says Unreachable";
    }
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // the number of rows in the section.
    return [self.imageURLs count];
}

- (AFHTTPRequestOperationManager *)operationManager
{
    if (!_operationManager)
    {
        _operationManager = [[AFHTTPRequestOperationManager alloc] init];
        _operationManager.responseSerializer = [AFImageResponseSerializer serializer];
    };

    return _operationManager;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell"forIndexPath:indexPath];

    cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
    cell.textLabel.numberOfLines = 0;
    cell.textLabel.font = [UIFont systemFontOfSize:13.0];

    cell.textLabel.text = [Titoli objectAtIndex:indexPath.row];

    if (_verificaConnessione == 1)
    {
        cell.userInteractionEnabled = NO;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.imageView.image = [UIImage imageNamed:@"imagefailed.png"];

        CGSize itemSize = CGSizeMake(60, 60);
        UIGraphicsBeginImageContextWithOptions(itemSize, NO, UIScreen.mainScreen.scale);
        CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
        [cell.imageView.image drawInRect:imageRect];
        cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    }
    else
    {
        cell.imageView.image = [UIImage imageNamed:@"loading.png"];

        CGSize itemSize = CGSizeMake(60, 60);
        UIGraphicsBeginImageContextWithOptions(itemSize, NO, UIScreen.mainScreen.scale);
        CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
        [cell.imageView.image drawInRect:imageRect];
        cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

        NSString *url = self.imageURLs[indexPath.row];

        cell.imageView.associatedObject = url;

        [self.operationManager GET:url
                        parameters:nil
                           success:^(AFHTTPRequestOperation *operation, id responseObject) {
                               if ([cell.imageView.associatedObject isEqualToString:url])
                               {
                                   cell.imageView.image = responseObject;
                               }
                           } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                               NSLog(@"Failed with error %@.", error);
                           }];
    }

    return cell;
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([[segue identifier] isEqualToString:@"ShowDetails"]) {

        NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
        CollectionViewController *collection = [segue destinationViewController];
        collection.valore = [Titoli objectAtIndex:selectedRowIndex.row];
    }}

COLLECTIONVIEWCONTROLLER.H

#import <UIKit/UIKit.h>

@interface CollectionViewController : UICollectionViewController

@property (nonatomic, strong) NSArray *valore;

@end

这是我的故事板 http://i.imgur.com/ckJWPEd.jpg

1 个答案:

答案 0 :(得分:0)

您必须实施方法didSelectRowAtIndexPath,并且在此方法中使用例如performSegueWithIdentifier,其标识符应为"ShowDetails",因为它已在您的代码中编写