TableView to detailTableView - 落后一步

时间:2013-01-22 13:31:41

标签: iphone tableview master-detail

当我将my tableView连接到detailtableView时,我得到的错误是detailtableView落后一步。例如,当单击mastertableView中的第二个单元格时,它会显示第一个单元格detailInformation。希望你能理解我的问题。

见我的.m。

#import "GuideTableViewController.h"
#import "GuideDetailTableViewController.h"

@interface GuideTableViewController (){
    NSArray *guide;

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

@end

@implementation GuideTableViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


//JSONmetod
- (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/test.json"]];

        NSError *error;

        if (data)
        {

            guide = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];

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


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




            dispatch_sync(dispatch_get_main_queue(), ^{
                // code
                [self.tableView reloadData];
            });


    });


    }




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

    //Anropa json

    [self loadJSON];
}

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


//TableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return guide.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];


    NSDictionary *dict = [guide objectAtIndex:indexPath.row];
    cell.textLabel.text = [dict valueForKey:@"title"];

    return cell;
}


//Till detailView

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    if ([segue.identifier isEqualToString:@"showStay"]){
        GuideDetailTableViewController *tvc = [segue destinationViewController];
        NSIndexPath *index = sender;
        NSDictionary *dict = [guide objectAtIndex:index.row];

        tvc.stay = dict;
    }
}

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

    [self performSegueWithIdentifier:@"showStay" sender:indexPath];


}




@end

提前致谢!

1 个答案:

答案 0 :(得分:1)

您使用didDeselectRowAtIndexPath代替didSelectRowAtIndexPath委托方法,常见的自动填充错误。