自定义tableViewController不推送数据

时间:2014-10-10 23:36:53

标签: ios objective-c

我有自定义表视图控制器,当我尝试将一些细节推送到另一个视图时,它总是推送我的数组的第一个元素,这是我尝试过的可能的代码,

我希望当我单击任何单元格时,单元格的索引路径行将发送到其他视图。

#import "ModelsViewController.h"

@interface ModelsViewController ()

@end

@implementation ModelsViewController

- (void)viewDidLoad {
    [super viewDidLoad];


    id delegate =[[UIApplication sharedApplication]delegate];
    NSError*error=nil;

    NSManagedObjectContext *context = [delegate managedObjectContext];



    // Test listing all FailedBankInfos from the store
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Subjects"
                                              inManagedObjectContext:context];
    [fetchRequest setEntity:entity];

    NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
    self.models  =[[[NSArray alloc]initWithArray:fetchedObjects]valueForKey:@"modelName"];
    self.modelId =[[[NSArray alloc]initWithArray:fetchedObjects]valueForKey:@"modelCode"];
    self.teacher =[[[NSArray alloc]initWithArray:fetchedObjects]valueForKey:@"teacher"];


}

- (void)didReceiveMemoryWarning

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


-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{

    return 0;

}



- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    // This will create a "invisible" footer
    return 0.01f;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return [self.models count];
}


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


    static NSString * cellIdnt =@"MyCell";

    ModlesTableViewCell *cell =(ModlesTableViewCell *) [tableView dequeueReusableCellWithIdentifier:cellIdnt forIndexPath:indexPath];

    // Configure the cell...

    cell.detailTextLabel.text=[self.teacher objectAtIndex:indexPath.row];
    cell.textLabel.text=      [self.models objectAtIndex:indexPath.row];

    return cell;
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 78;
}

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {


    if ([[segue identifier]isEqualToString:@"ShowTimes"])
    {
        ShowTimesTableViewController * timesView =[segue destinationViewController];

        NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];

        timesView.modelID=[self.modelId objectAtIndex:myIndexPath.row];
        timesView.modelNAme=[self.models objectAtIndex:myIndexPath.row];
    }

}

0 个答案:

没有答案