I am new in iOS and I am facing problem in custom table view. I am using custom table view cell
AuditTableviewcell.h
{
NSString *ActualString;
IBOutlet UIButton *infobtn;
UITextField * alertTextField;
UITextView *textView1;
UILabel *lbl;
}
-(IBAction)passbtnClick:(id)sender;
-(IBAction)failbtnClick:(id)sender;
-(IBAction)wipbtnClick:(id)sender;
-(IBAction)nabtnClick:(id)sender;
-(IBAction)infobtnClick:(id)sender;
@property(nonatomic,strong)IBOutlet UILabel *audittitlelbl;
@property(nonatomic,strong)IBOutlet UILabel *listlbl;
@property(nonatomic,strong) IBOutlet UILabel *passlbl;
@property(nonatomic,strong) IBOutlet UILabel *faillbl;
@property(nonatomic,strong) IBOutlet UILabel *warninglbl;
@property(nonatomic,strong) IBOutlet UILabel *nalbl;
@property(nonatomic,strong) IBOutlet UILabel *actuallbl;
@property(nonatomic,strong) IBOutlet UILabel *nameidlbl;
@property(nonatomic,strong) IBOutlet UILabel *remarklbl;
@property(nonatomic,strong) IBOutlet UIButton *passbtn;
@property(nonatomic,strong) IBOutlet UIButton *failbtn;
@property(nonatomic,strong) IBOutlet UIButton *wipbtn;
@property(nonatomic,strong) IBOutlet UIButton *nabtn;
AuditTableviewcell.m
@synthesize audittitlelbl,listlbl,passbtn,nabtn,passlbl,faillbl,warninglbl,nalbl,actuallbl,failbtn,wipbtn,nameidlbl;
- (void)awakeFromNib {
passbtn.layer.cornerRadius = passbtn.bounds.size.width / 2.0;// this value vary as per your desire
passbtn.clipsToBounds = YES;
failbtn.layer.cornerRadius = failbtn.bounds.size.width / 2.0;// this value vary as per your desire
failbtn.clipsToBounds = YES;
wipbtn.layer.cornerRadius = wipbtn.bounds.size.width / 2.0;// this value vary as per your desire
wipbtn.clipsToBounds = YES;
nabtn.layer.cornerRadius = nabtn.bounds.size.width / 2.0;// this value vary as per your desire
nabtn.clipsToBounds = YES;
infobtn.layer.cornerRadius = infobtn.bounds.size.width / 2.0;// this value vary as per your desire
[[infobtn layer] setBorderWidth:1.0f];
infobtn.layer.borderColor =[[UIColor blueColor] CGColor];
infobtn.clipsToBounds = YES;
passlbl.hidden=YES;
faillbl.hidden=YES;
warninglbl.hidden=YES;
nalbl.hidden=YES;
actuallbl.hidden=YES;
nameidlbl.hidden=YES;
// Initialization code
}
- (void)textViewDidEndEditing:(UITextView *)theTextView
{
if (![textView1 hasText]) {
lbl.hidden = NO;
}
}
- (void) textViewDidChange:(UITextView *)textView
{
if(![textView hasText]) {
lbl.hidden = NO;
}
else{
lbl.hidden = YES;
}
}
-(IBAction)passbtnClick:(id)sender
{
passbtn.backgroundColor=[UIColor greenColor];
failbtn.backgroundColor=[UIColor lightGrayColor];
wipbtn.backgroundColor=[UIColor lightGrayColor];
nabtn.backgroundColor=[UIColor lightGrayColor];
actuallbl.text=passlbl.text;
ActualString=actuallbl.text;
}
-(IBAction)failbtnClick:(id)sender
{
passbtn.backgroundColor=[UIColor lightGrayColor];
failbtn.backgroundColor=[UIColor redColor];
wipbtn.backgroundColor=[UIColor lightGrayColor];
nabtn.backgroundColor=[UIColor lightGrayColor];
actuallbl.text=faillbl.text;
ActualString=actuallbl.text;
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
[defaults setObject:ActualString forKey:@"ActualStringCustom"];
UIAlertView *testAlert = [[UIAlertView alloc] initWithTitle:@"Fail!"
message:audittitlelbl.text
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Done", nil];
textView1 = [UITextView new];
lbl = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 0.0,90.0, 34.0)];
[lbl setText:@"Enter Remark"];
[lbl setFont:[UIFont systemFontOfSize:12]];
[lbl setBackgroundColor:[UIColor clearColor]];
[lbl setTextColor:[UIColor lightGrayColor]];
textView1.delegate = self;
[textView1 addSubview:lbl];
[testAlert setValue: textView1 forKey:@"accessoryView"];
[testAlert show];
}
-(IBAction)wipbtnClick:(id)sender
{
passbtn.backgroundColor=[UIColor lightGrayColor];
failbtn.backgroundColor=[UIColor lightGrayColor];
wipbtn.backgroundColor=[UIColor orangeColor];
nabtn.backgroundColor=[UIColor lightGrayColor];
actuallbl.text=warninglbl.text;
ActualString=actuallbl.text;
UIAlertView *testAlert = [[UIAlertView alloc] initWithTitle:@"Warning!"
message:audittitlelbl.text
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Done", nil];
textView1 = [UITextView new];
lbl = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 0.0,90.0, 34.0)];
[lbl setText:@"Enter Remark"];
[lbl setFont:[UIFont systemFontOfSize:12]];
[lbl setBackgroundColor:[UIColor clearColor]];
[lbl setTextColor:[UIColor lightGrayColor]];
textView1.delegate = self;
[textView1 addSubview:lbl];
[testAlert setValue: textView1 forKey:@"accessoryView"];
[testAlert show];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if(buttonIndex==0)
{
}
}
-(IBAction)nabtnClick:(id)sender
{
passbtn.backgroundColor=[UIColor lightGrayColor];
failbtn.backgroundColor=[UIColor lightGrayColor];
wipbtn.backgroundColor=[UIColor lightGrayColor];
nabtn.backgroundColor=[UIColor blueColor];
actuallbl.text=nalbl.text;
ActualString=actuallbl.text;
}
-(IBAction)infobtnClick:(id)sender
{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"info" message:@"Information to be displayed" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
ViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *STI=@"STI";
AuditTableViewCell *cell = (AuditTableViewCell *)[tableView dequeueReusableHeaderFooterViewWithIdentifier:STI];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AuditTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
cell.accessoryType=UITableViewCellAccessoryNone;
}
cell.audittitlelbl.text=[NSString stringWithFormat:@"%@",[idarray objectAtIndex:indexPath.row]];
cell.nameidlbl.text=[NSString stringWithFormat:@"%@",[CheckpointNameIDArray objectAtIndex:indexPath.row]];
cell.passlbl.text=[NSString stringWithFormat:@"%@",[Passarray objectAtIndex:indexPath.row]];
cell.faillbl.text=[NSString stringWithFormat:@"%@",[Failarray objectAtIndex:indexPath.row]];
cell.warninglbl.text=[NSString stringWithFormat:@"%@",[Warningarray objectAtIndex:indexPath.row]];
cell.nalbl.text=[NSString stringWithFormat:@"%@",[NAarray objectAtIndex:indexPath.row]];
[cell.passbtn addTarget:self action:@selector(btnQuantityPressedPass:) forControlEvents:UIControlEventTouchUpInside];
[cell.failbtn addTarget:self action:@selector(btnQuantityPressedFail:) forControlEvents:UIControlEventTouchUpInside];
[cell.wipbtn addTarget:self action:@selector(btnQuantityPressedWarning:) forControlEvents:UIControlEventTouchUpInside];
[cell.nabtn addTarget:self action:@selector(btnQuantityPressedNA:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView.layer setBorderColor:[UIColor blackColor].CGColor];
[cell.contentView.layer setBorderWidth:0.5f];
return cell;
}
//TODO: PassButton from Cell method
-(void)btnQuantityPressedPass:(UIButton *)sender
{
AuditTableViewCell *cell = sender.superview.superview;
NSString *String =cell.actuallbl.text;
NSString *String2=cell.nameidlbl.text;
NSString *FailString=@"";
NSString *WarningString=@"";
NSLog(@"String =%@",String);
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
[defaults setObject:String forKey:@"ActualStringCustom"];
[defaults setObject:String2 forKey:@"CheckPointNameID"];
NSManagedObjectContext *context = [self managedObjectContext];
NSError *error;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"AuditPost" inManagedObjectContext:context]];
// NSError *error = nil;
NSArray *results = [context executeFetchRequest:request error:&error];
NSLog(@"Result =%@",results);
ComplareArray=[devices valueForKey:@"checkpointid"];
BOOL contains = [ComplareArray containsObject:String2];
if(contains == NO)
{
if (self.device) {
// Update existing device
[device setValue:Audit forKey:@"auditnameId"];
[device setValue:String forKey:@"checklistid"];
[device setValue:String2 forKey:@"checkpointid"];
[device setValue:FailString forKey:@"failreason"];
[device setValue:WarningString forKey:@"warningreason"];
[device setValue:AuditStartDate forKey:@"starttimedate"];
[device setValue:userid forKey:@"userid"];
NSError *error = nil;
// Save the object to persistent store
if (![context save:&error]) {
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
}
} else {
// Create a new device
NSManagedObject *newDevice = [NSEntityDescription insertNewObjectForEntityForName:@"AuditPost" inManagedObjectContext:context];
[newDevice setValue:Audit forKey:@"auditnameId"];
[newDevice setValue:String forKey:@"checklistid"];
[newDevice setValue:String2 forKey:@"checkpointid"];
[newDevice setValue:FailString forKey:@"failreason"];
[newDevice setValue:WarningString forKey:@"warningreason"];
[newDevice setValue:AuditStartDate forKey:@"starttimedate"];
[newDevice setValue:userid forKey:@"userid"];
NSError *error = nil;
// Save the object to persistent store
if (![context save:&error]) {
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
}
}
}
else
{
NSError *error = nil;
// Save the object to persistent store
if (![context save:&error]) {
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
}
///
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"AuditPost" inManagedObjectContext:context]];
// NSError *error = nil;
NSArray *results = [context executeFetchRequest:request error:&error];
NSManagedObject* favoritsGrabbed = [results objectAtIndex:CurrentIndexPath];
[favoritsGrabbed setValue:String forKey:@"checklistid"];
// Save the