2013-06-24 69 views
0

我有一個應用程序,你可以在其中有一些東西的細節,然後在那個東西里面你有一個子類別的東西。我做了一個按鈕,因爲沒有足夠的空間放置導航項目,我似乎無法僅調用分配給我的nsmutablearray中的項目。我曾嘗試使用initWithIndexPath:indexPath.row儘管這個錯誤出現:IndexPath.row在按鈕上?

Use of undeclared identifyer "indexPath"; did you mean "NSIndexPath"

這是我的tableView我的tableView裏面的代碼:

#import "PRViewController.h" 

#import "Patient.h" 

#import "LSAppDelegate.h" 

#import "LSViewController.h" 

#import "LSAppDelegate.h" 

#import "Patient.h" 

#import "PatientController.h" 

#import "AddPatientController.h" 

#import "treatmentController.h" 

@interface PRViewController() 

@end 

@implementation PRViewController 

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

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.navigationItem.rightBarButtonItem = self.editButtonItem; 
    self.title = @"Treatments"; 
    LSAppDelegate *delegate = (LSAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    patients = delegate.patients; 
    [[UIToolbar appearance] setTintColor:[UIColor brownColor]]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

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

-(IBAction)add:(id) sender{ 

    [self.tableView reloadData]; 
    [self.tableView setEditing:YES animated:YES]; 
    if(self.tableView) { 
     NSMutableArray *indices = [[NSMutableArray alloc] init]; 
     for (int i=0; i < patients.count; i++) { 
      [indices addObject:[NSIndexPath indexPathForRow:i inSection:0]]; 

     } 
     NSArray *lastIndex = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:patients.count inSection:0]]; 
     if (self.tableView) { 
      for (int i=0; i < patients.count; i++) { 
       UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[indices objectAtIndex:i]]; 
       [cell setSelectionStyle:UITableViewCellSelectionStyleBlue]; 
      } 
     } 
    } 
    [self.tableView setEditing:NO animated:YES]; 
    treatmentController *AddPatient = [[treatmentController alloc] init]; 
    [self.navigationController pushViewController:AddPatient animated:YES]; 
    [super setEditing:NO animated:NO]; 
} 

-(void)setEditing:(BOOL)editing animated:(BOOL) animated { 
    if (editing != self.editing) { 
     [super setEditing:editing animated:animated]; 
     [self.tableView setEditing:editing animated:animated]; 

    } 
} 

#pragma mark UITableViewDataSource Methods 

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:@"cell"]; 
    if (nil == cell) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; 
    } 

    NSLog(@"indexPath.row = %d, patients.count = %d", indexPath.row, patients.count); 
    Patient *thisPatient = [patients objectAtIndex:indexPath.row]; 
    if (thisPatient.treatmentName.length > 0) { 
     cell.textLabel.text = thisPatient.treatmentName; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
     cell.textLabel.textColor = [UIColor blackColor]; 
    } else { 

    } 
    if (self.editing) { 
     [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
    } 
    return cell; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [patients count]; 
} 

#pragma mark UITableViewDelegate Methods 

- (void) tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     [patients removeObjectAtIndex:indexPath.row]; 
     [tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft]; 
    } 
} 

- (void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    LSAppDelegate *delegate = (LSAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    PatientController *patient = [[PatientController alloc] initWithIndexPath:indexPath]; 
    [delegate.navController pushViewController:patient animated:YES]; 
    [tv deselectRowAtIndexPath:indexPath animated:YES]; 
} 
@end 

請說,如果你想要更多的代碼或信息請儘快回答,因爲你可以

文件按鈕,我用力推:

#import "PatientController.h" 

#import "LSAppDelegate.h" 

#import "Patient.h" 

#import "PRViewController.h" 

@interface PatientController() 

@end 

@implementation PatientController 



- (id)initWithIndexPath:(NSIndexPath *)indexPath { 

    if ((self = [super init])) { 
     index = indexPath; 
    } 
    return self; 
} 

- (IBAction)PatientRecords:(id)sender { 
    PRViewController *AddPatient = [[PRViewController alloc] initWithIndexPath:indexPath.row]; 
    [self.navigationController pushViewController:AddPatient animated:YES]; 

} 

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


- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    LSAppDelegate *delegate = (LSAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    Patient *thisPatient = [delegate.patients objectAtIndex:index.row]; 
    self.navigationItem.rightBarButtonItem = self.editButtonItem; 
    self.title = thisPatient.patientName; 
    patientNameView.text = thisPatient.patientName; 
    patientFirstNameView.text = @"Firstname:"; 
    patientSurnameView.text = thisPatient.patientSurname; 
    patientSurnameNameView.text = @"Surname:"; 
    patientDoBView.text = thisPatient.patientDoB; 
    patientDoBDateView.text = @"Date of Birth:"; 
    patientHomeView.text = thisPatient.patientHomeNumber; 
    patientHomeNumberView.text = @"Home No:"; 
    patientMobileView.text = thisPatient.patientMobileNumber; 
    patientMobileNumberView.text = @"Mobile No:"; 
    patientAddressView.text = thisPatient.patientAddress; 
    patientAddressView.editable = NO; 
    patientAddressPlaceNumberView.text = @"Address:"; 
    patientEmailView.text = thisPatient.patientEmail; 
    patientEmailAddressView.text = @"Email:"; 

    patientPictureView.image = thisPatient.patientPicture; 
    // Do any additional setup after loading the view from its nib. 
} 

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

-(void)setEditing:(BOOL)editing animated:(BOOL) animated { 
    if (editing != self.editing) { 
     [super setEditing:editing animated:animated]; 
     patientAddressView.editable = YES; 
    } 
} 

@end 

在此先感謝

+0

顯示我們的代碼。 –

+0

哪些文件? – Hive7

+0

你的應用程序正在崩潰。 –

回答

0
- (IBAction)PatientRecords:(id)sender { 
    PRViewController *AddPatient = [[PRViewController alloc] initWithIndexPath:indexPath.row]; 
    [self.navigationController pushViewController:AddPatient animated:YES]; 
} 

該代碼看起來是罪魁禍首,你不聲明變量indexPath的任何地方,你需要使用index而不是indexpath從我所看到的。

+0

感謝它的工作。我將indexPath更改爲索引 – Hive7

0
Use of undeclared identifyer "indexPath"; did you mean "NSIndexPath" 

如果不申報indexPath而是嘗試使用它此錯誤只發生。由於Xcode編譯器的代碼感覺檢測並顯示您提示它可能是NSIndexPath而不是indexPath。檢查indexPath的使用和聲明。