简体   繁体   English

在一个按钮上的IndexPath.row?

[英]IndexPath.row on a button?

I have an app in which you can have some details of something and then inside that thing you have a sub-category of things. 我有一个应用程序,您可以在其中包含某些内容的详细信息,然后在该内容中包含一个子类别。 I have made a button as there was not enough room for a navigation item and I can't seem to be able to call only the items that are assigned to that in my nsmutablearray. 我做了一个按钮,因为没有足够的空间容纳导航项目,而且我似乎无法仅调用nsmutablearray中分配给该项目的项目。 I have tried to used initWithIndexPath:indexPath.row though it comes up with this error: 我尝试使用initWithIndexPath:indexPath.row尽管它带有以下错误:

Use of undeclared identifyer "indexPath"; 使用未声明的标识符“ indexPath”; did you mean "NSIndexPath" 你的意思是“ NSIndexPath”

This is the code for my tableView inside my tableView: 这是我的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

Please say if you want any more code or information and please answer as soon as you can 请说出您是否需要更多代码或信息,请尽快回答

file for the button I am pushing with: 我按下的按钮的文件:

#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

Thanks in advance 提前致谢

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

This error only happen if your do not declare indexPath but try to use it. 仅当您未声明indexPath而是尝试使用它时,才会发生此错误。 As Xcode compiler's code sense detect and show you hint that it may be NSIndexPath instead of indexPath. 当Xcode编译器的代码感知检测并显示出提示时,它可能是NSIndexPath而不是indexPath。 check the use and declaration of indexPath. 检查indexPath的使用和声明。

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

This code looks to be the culprit, you're not declaring the variable indexPath anywhere, you need to use index rather than indexpath from what I can see. 这段代码似乎是罪魁祸首,您没有在任何地方声明变量indexPath ,您需要使用index而不是我所看到的indexpath

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM