2013-02-15 3 views
0

У меня есть 3 разных подробных элемента отображения, которые мои ячейки в моем masterTableView вызовут при касании.DidSelectRowAtIndexPath не называется

Пожалуйста, смотрите мой master.m файл:

#import "GuideTableViewController.h" 
#import "GuideDetailTableViewController.h" 
#import "GuideDetailTableViewController2.h" 
#import "GuideDetailTableViewController3.h" 
#import <QuartzCore/QuartzCore.h> 

@interface GuideTableViewController(){ 

    NSMutableData *weatherResponseData; 

    NSArray *headGuide; 

    NSArray *leftImages; 

} 

@property (weak, nonatomic) IBOutlet UITableView *tableView; 

@property (weak, nonatomic) IBOutlet UIImageView *imgHeader; 

@property (weak, nonatomic) IBOutlet UIImageView *ImgTitle; 

@property (weak, nonatomic) IBOutlet UIImageView *ImgWeather; 

@property (weak, nonatomic) IBOutlet UIButton *btnMap; 

@property (weak, nonatomic) IBOutlet UILabel *LabelWeather; 

@property (weak, nonatomic) IBOutlet UILabel *LabelWeather2; 

@end 

@implementation GuideTableViewController 


//Weather method 

- (void) loadWeather{ 

    NSURLRequest *theRequest = [NSURLRequest requestWithURL: 
           [NSURL URLWithString:@"http://api.wunderground.com/api/3919480da5014c98/conditions/q/BR/Sao_Sebastiao .json"]]; 
    NSURLConnection *theConnection=[[NSURLConnection alloc] 
           initWithRequest:theRequest delegate:self]; 
    if(theConnection){ 
     weatherResponseData = [[NSMutableData alloc] init]; 
    } else { 
     NSLog(@"failed"); 
    } 
} 

//Delegates for WeatherData 

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
    [weatherResponseData setLength:0]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    [weatherResponseData appendData:data]; 
} 

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 
    NSString *msg = [NSString stringWithFormat:@"Failed: %@", [error description]]; 
    NSLog(@"%@",msg); 
} 


- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    NSError *myError = nil; 
    NSDictionary *res = [NSJSONSerialization JSONObjectWithData:weatherResponseData options:NSJSONReadingMutableLeaves error:&myError]; 
    NSArray *results = [res objectForKey:@"current_observation"]; 
    NSString *cur = [results valueForKey:@"weather"]; 
    NSString *tmp = [results valueForKey:@"temperature_string"]; 
    NSString *wind = [results valueForKey:@"wind_string"]; 

    NSLog(@"Current conditions: %@, %@º, %@", cur, tmp, wind); 

    self.LabelWeather.text = cur; 

    self.LabelWeather2.text = tmp; 
} 


//JSONmethod 

- (void) loadJSON{ 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
     //code 
     NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://dl.dropbox.com/u/100670549/guide.json"]]; 

     NSError *error; 

     if (data) 
     { 
      headGuide = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; 

      for (NSDictionary *dictionary in headGuide){ 
       // NSLog([dictionary description]); 
      } 

     }else 
     { 
      NSLog(@"Could not load data"); 
     } 

     dispatch_sync(dispatch_get_main_queue(), ^{ 
      // code 

      [self.tableView reloadData]; 
     }); 
    }); 
} 


//Load 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 


    [self loadJSON]; 
    [self loadWeather]; 

    leftImages = [NSArray arrayWithObjects:@"btn_Stay.png", @"btn_Eat.png", @"btn_Todo.png", nil]; 


    // set background 
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.jpg"]]; 

    // rounded corners 

    [self.tableView.layer setCornerRadius:9.0]; 

    [self.ImgWeather.layer setCornerRadius:9.0]; 
} 


#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. 
    return headGuide.count; 
} 

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 


    NSArray *dict = [headGuide objectAtIndex:indexPath.row]; 

    cell.textLabel.text = [dict valueForKey:@"title"]; 

    NSString *cellImage = [leftImages objectAtIndex:indexPath.row]; 
    UIImage *cellIcon = [UIImage imageNamed:cellImage]; 

    cell.imageView.image = cellIcon; 

    return cell; 
} 


- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ 
    if ([segue.identifier isEqualToString:@"whereStay"]){ 
     GuideDetailTableViewController *vc = [segue destinationViewController]; 
     NSIndexPath *index = sender; 
     NSDictionary *dict = [headGuide objectAtIndex:index.row]; 
     vc.stayGuide = dict; 
    } 
    else if ([segue.identifier isEqualToString:@"whereEat"]){ 
     GuideDetailTableViewController2 *vc1 = [segue destinationViewController]; 
     NSIndexPath *index = sender; 
     NSDictionary *dict = [headGuide objectAtIndex:index.row]; 
     vc1.eatGuide = dict; 
    } 
    else if ([segue.identifier isEqualToString:@"whatTodo"]){ 
     GuideDetailTableViewController3 *vc2 = [segue destinationViewController]; 
     NSIndexPath *index = sender; 
     NSDictionary *dict = [headGuide objectAtIndex:index.row]; 
     vc2.todoGuide = dict; 
    } 
} 


#pragma mark - tableView delegate 

- (void)tableView:(UITableView *)tableView didselectRowAtIndexPath:(NSIndexPath  *)indexPath{ 
    if(indexPath.row == 0){ 
     [self performSegueWithIdentifier:@"whereStay" sender:indexPath]; 
    }else if(indexPath.row ==1){ 
     [self performSegueWithIdentifier:@"whereEat" sender:indexPath]; 
    }else{ 
     [self performSegueWithIdentifier:@"whatTodo" sender:indexPath]; 
    } 

    [tableView setAllowsSelection:YES]; 
} 

@end 

ответ

2

Ваш метод подписи тоже не правильно капитализируются:

- (void)tableView:(UITableView *)tableView didselectRowAtIndexPath:(NSIndexPath  *)indexPath{ 

должен быть

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath  *)indexPath{ 

Имена методов чувствительны к регистру.

Кроме того, убедитесь, что вы устанавливаете делегата в Tableview с

self.tableView.delegate = self; 
+0

Это было так ... так легко и потребовалось так долго, чтобы узнать ... стыд. Большое спасибо @Tim! –

+0

Стандартная процедура в StackOverflow - это щелкнуть галочку рядом с ответом, который помог вам пометить его как правильно. – Tim

+0

Сделано..отчет снова. –

1

Это не выглядит, как вы устанавливаете этот объект в качестве делегата от вашей точки зрения таблицы. В вашем методе -viewDidLoad, вы должны вызвать [[self tableView] setDelegate:self];

+0

Да, это был так. Благодаря! –

1

Где ваш протокол Tableview делегат и источник данных?

@interface GuideTableViewController : UIViewController <UITableViewDataSource,UITableViewDelegate> 
{ 
//Attributes... 
IBOutlet UITableView *tableView; 
} 

в viewDidLoad, вы должны установить делегатов:

tableView.delegate = self; 
tableView.dataSource = self; 

вы могли бы также набор делегатов в XIb файлов ...

Так что ваши делегаты Методы должны работает ... Проверьте с apple docs about tableview: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html

Смежные вопросы