2 Replies - 2922 Views - Last Post: 16 July 2013 - 11:45 AM

#1 Hive7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-July 13

Error when loading data from array Objective-c

Posted 16 July 2013 - 11:17 AM

I have an array that I am using to put the data into a tableView though even though I know the data is there it is not being shown.

Here is the code for the .h file:

#import <UIKit/UIKit.h>

@interface ManageTreatmentController : UIViewController <UITableViewDataSource, UITableViewDelegate> {
    NSMutableArray *treatments;
    NSIndexPath *index;
}


@property (strong, nonatomic) IBOutlet UITableView *tableView;

- (IBAction)add:(id)sender;

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

@end




And my .m:

- (id)initWithIndexPath:(NSIndexPath *)indexPath {
    
    if ( ( self = [super init]) ) {
        index = indexPath;
    }
    return self;
}

- (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];
    treatments = delegate.treatments;
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
    [self.tableView reloadData];
    // 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 ) {
        if (treatments.count == 0) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oops!!!" message:@"There are no items to delete" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
            [alert show];
        } else {
            [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, treatments.count);
    Treatment *thisTreatment = [treatments objectAtIndex:indexPath.row];
    if (thisTreatment.treatmentName.length > 0) {
        cell.textLabel.text = thisTreatment.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 [treatments count];
}

#pragma mark UITableViewDelegate Methods

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

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


- (IBAction)add:(id)sender {
    AddTreatmentName *patient = [[AddTreatmentName alloc] initWithIndexPath:index];
    [self.navigationController pushViewController:patient animated:YES];

}




Thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: Error when loading data from array Objective-c

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13400
  • View blog
  • Posts: 53,476
  • Joined: 12-June 08

Re: Error when loading data from array Objective-c

Posted 16 July 2013 - 11:40 AM

Typically it is helpful to tell folks the entire error message as well as what line it says it is occurring on.
Was This Post Helpful? 0
  • +
  • -

#3 Hive7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-July 13

Re: Error when loading data from array Objective-c

Posted 16 July 2013 - 11:45 AM

There is no error it just doesn't load
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1