Xcode - Segue issues

三世轮回 提交于 2020-02-16 06:38:23

问题


i've been trying to get a segue to work. I've written the following... but for some reason, the ...preparesegue... method doesnt fire. I've read other related posts but i cant get it to fire, and just as importantly, the variable i'm need isnt transferred.

m file:

@implementation CountryTableViewController


-(void) getData:(NSData *) data {
    NSError *error;
    json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
    [self.tableView reloadData];
}
-(void) start {
    NSURL *url = [NSURL URLWithString: URL];
    NSData *data = [NSData dataWithContentsOfURL:url];
    [self getData:data];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self start];
}

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

#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 [json count];
}


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

    static NSString *cellId = @"CellIdentifier";

    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId];
    }
    NSDictionary *info = [json objectAtIndex:indexPath.row];

    cell.TitleLabel.text = [info objectForKey:@"CountryName"];
    cell.ReferenceLabel.text = [info objectForKey:@"id"];

    return cell;
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender tableView:(UITableView *)tableView {
    //if ([segue.identifier isEqualToString:@"CountryToState"]) {
    NSLog(@"TEST");
    NSIndexPath *path = [self.tableView indexPathForSelectedRow];

    TableViewCell *cell = (TableViewCell *)[tableView cellForRowAtIndexPath:path];
    NSString *countryRef = [[cell ReferenceLabel] text];

    TableViewControllerStates *TVCS = [segue destinationViewController];
    TVCS.receivedReferenceNumber = countryRef;
    //}
}

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


    //TableViewCell *cell = (TableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
    //NSString *countryRefNumber = [[cell ReferenceLabel] text];
    [self performSegueWithIdentifier:@"CountryToState" sender:tableView];

}

h file

#import <UIKit/UIKit.h>
#define URL @"http://localhost/Rs.php"

@interface CountryTableViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> {
    NSMutableArray *json;
}

Any help appreciated; thank you in advance.

来源:https://stackoverflow.com/questions/33058397/xcode-segue-issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!