Domanda

I am using Delegate method to access my table view's cell's information for button click methods.my table view cells are customised. i have design the cells in a separate xib file and also declare a tableViewCell type class for the cell.and given that class to the cell which i have designed. I am loading different cell designs according to a date and some other conditions in the same table view. But the problem is when i click a button inside my cell, it is not working. I have put a break point to the place where the code is, but it is not going to the breakpoint.

Here is the steps i followed. It was worked fine when i designed my table cell inside the prototype cell using storyboards. I did the same thing using xib, but i don't know what is the wrong.

this is my customised cell's .h class which i declare the delegate #import

@class CellForComingDates;

@protocol ComingDateRowDelegate <NSObject>

-(void)DeleteButtonAction_new:(CellForComingDates*)cell;


@end


@interface CellForComingDates : UITableViewCell

@property (strong, nonatomic) IBOutlet UIImageView *cellImage;
@property (strong, nonatomic) IBOutlet UILabel *personName;
@property (strong, nonatomic) IBOutlet UILabel *appoinmentTime;
@property (strong, nonatomic) IBOutlet UILabel *appoinmentDate;
@property (strong,nonatomic) NSString* appoinmentstartTime;
@property (strong,nonatomic) NSString* appoinmentendTime;
@property (strong,nonatomic) NSString* appoinmentID;
@property (strong,nonatomic) NSString* USER;

@property (weak) id<ComingDateRowDelegate> comingDateDel;


@end

Here is the .m class which my IBAction method is included. and i have connect the IBaction to the button correctly

- (IBAction)DeleteButton:(id)sender {
[self.comingDateDel DeleteButtonAction_new:self];
}

Then, inside the tableView class, i have implemented the click method

-(void)DeleteButtonAction_new:(CellForComingDates*)cell{
     AppoinmentID = cell.appoinmentID;
   UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Delete Appoinment"
                                                message:@"click ok to delete"
                                               delegate:self
                                      cancelButtonTitle:@"OK"
                                      otherButtonTitles:@"Cancel",nil];
alert.tag = kAlertViewTwo;
[alert show];
}

but when i click the button it is not responding... can someone tell me what happened here ?

thank you

EDIT

here is my cellForRowAtIndexpath method

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

{

UITableViewCell *cell;
NSDate *today = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    // display in 12HR/24HR (i.e. 11:25PM or 23:25) format according to User Settings
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
NSString *currentTime = [dateFormatter stringFromDate:today];
NSDate *date=[dateFormatter dateFromString:currentTime];

if(indexPath.row==0){
    VCPerson *person = self.persons[0];

    cell = [self createPersonCell:person];

}

else if ([self datePickerIsShown] && (self.datePickerIndexPath.row == 1)){

    cell = [self createPickerCell:date];

}

else{

    NSDictionary* detailsToShowTemp= [[ScheduleView getRequestForDate]objectAtIndex:indexPath.row-1];
    NSInteger Mailcount = [[[detailsToShowTemp valueForKey:@"Appointment" ]valueForKey:@"SentMailCount"] integerValue];
    NSInteger ReviewID = [[[detailsToShowTemp valueForKey:@"AppointmentReview" ]valueForKey:@"ReviewId"] integerValue];
    NSString* timestam = [[[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"DayTimeSlot"]valueForKey:@"Date"];
    NSString* dateText = [self ConvertDate:timestam];

    NSString* FirstName = [[detailsToShowTemp valueForKey:@"PatientProfile"]valueForKey:@"FirstName"];

    NSString* LastName = [[detailsToShowTemp valueForKey:@"PatientProfile"]valueForKey:@"LastName"];
    NSString* partioalImage = [[detailsToShowTemp valueForKey:@"PatientProfile"]valueForKey:@"ImageURL"];
    NSString* partioalImageURL=nil;

    if (![partioalImage isEqualToString:@""""]) {
        partioalImageURL = [partioalImage substringFromIndex:3];
    }
    else{
        partioalImageURL = @"images/profile-picture.png";
    }

    NSString* imageURL = [NSString stringWithFormat:@"%@%@",BaseURLString,partioalImageURL];
    NSURL *url = [NSURL URLWithString:imageURL];

    BOOL requestDateStatus = [self checkFutureDateRequest:dateText];

    if (requestDateStatus==NO) {
        if (Mailcount==0) {
            cellForDatePickCell *cell = (cellForDatePickCell*)[self.tableView dequeueReusableCellWithIdentifier:kOtherCellIdentifier];
            cell.delegate_Dtepick = self;

            //if (indexPath.row <= [ScheduleView getRequestForDate].count) {

            //NSLog(@"IndxPath.row : %ld",(long)indexPath.row);

            // NSDictionary* detailsToShowTemp= [[ScheduleView getRequestForDate]objectAtIndex:indexPath.row-1];




            cell.appoinment_Dtepick = [[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"AppointmentId"];

            cell.USER_Dtepick = [[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"UserId"];
            userID = cell.USER_Dtepick;


            cell.startTime_Dtepick =[[[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"DayTimeSlot"]valueForKey:@"StartTime"];
            cell.endTime_Dtepick =[[[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"DayTimeSlot"]valueForKey:@"EndTime"];
            cell.Time_Dtepick.text = [NSString stringWithFormat:@"%@ - %@",[[[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"DayTimeSlot"]valueForKey:@"StartTime"], [[[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"DayTimeSlot"]valueForKey:@"EndTime"]];




            cell.profileImage_Dtepick.imageURL = url;

            cell.Time_Dtepick.text = [NSString stringWithFormat:@"%@ - %@",[[[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"DayTimeSlot"]valueForKey:@"StartTime"], [[[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"DayTimeSlot"]valueForKey:@"EndTime"]];


            cell.Name_Dtepick.text = [NSString stringWithFormat:@"%@ %@",FirstName,LastName];

            cell.Date_Dtepick.text = dateText;

            return cell;

        }

        else if (ReviewID==0){
            NotReviewedCell *cell = (NotReviewedCell*)[tableView dequeueReusableCellWithIdentifier:@"NotReviewedCell"];
            cell.notReviewDelegate = self;
            if (! cell) {
                NSArray *parts = [[NSBundle mainBundle] loadNibNamed:@"NotReviewedCell" owner:nil options:nil];
                cell = [parts objectAtIndex:0];
            }
            cell.appoinmentID_green_Nreview = [[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"AppointmentId"];
            cell.USER_green_Nreview = [[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"UserId"];
            userID = cell.USER_green_Nreview;
            cell.appoinmentstartTime_green_Nreview =[[[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"DayTimeSlot"]valueForKey:@"StartTime"];
            cell.appoinmentendTime_green_Nreview =[[[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"DayTimeSlot"]valueForKey:@"EndTime"];

            cell.cellProfileImage.imageURL = url;

            cell.appoinmentTime_green_Nreview.text = [NSString stringWithFormat:@"%@ - %@",[[[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"DayTimeSlot"]valueForKey:@"StartTime"], [[[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"DayTimeSlot"]valueForKey:@"EndTime"]];

            cell.personName_green_Nreview.text = [NSString stringWithFormat:@"%@ %@",FirstName,LastName];

            cell.appoinmentDate_green_Nreview.text = dateText;

            return cell;
        }
        else{

            ReviewedCell *cell = (ReviewedCell*)[tableView dequeueReusableCellWithIdentifier:@"ReviewedCell"];
            cell.ReviewedDelegate = self;
            if (! cell) {
                NSArray *parts = [[NSBundle mainBundle] loadNibNamed:@"ReviewedCell" owner:nil options:nil];
                cell = [parts objectAtIndex:0];
            }
            cell.appoinmentID_Reviewed = [[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"AppointmentId"];
            cell.USER_Reviewed = [[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"UserId"];
            userID = cell.USER_Reviewed;
            cell.appoinmentstartTime_Reviewed =[[[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"DayTimeSlot"]valueForKey:@"StartTime"];
            cell.appoinmentendTime_Reviewed =[[[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"DayTimeSlot"]valueForKey:@"EndTime"];

            cell.ReviewedProfileImage.imageURL = url;

            cell.appoinmentTime_Reviewed.text = [NSString stringWithFormat:@"%@ - %@",[[[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"DayTimeSlot"]valueForKey:@"StartTime"], [[[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"DayTimeSlot"]valueForKey:@"EndTime"]];

            cell.personName_Reviewed.text = [NSString stringWithFormat:@"%@ %@",FirstName,LastName];

            cell.appoinmentDate_Reviewed.text = dateText;
            return cell;


        }
    }
    else{
        CellForComingDates *cell = (CellForComingDates*)[self.tableView dequeueReusableCellWithIdentifier:@"ComingDateCell"];
        //cell.comingDateDel =self;
        [cell setComingDateDel:self];
        if (! cell) {
            NSArray *parts = [[NSBundle mainBundle] loadNibNamed:@"comingDayCell" owner:nil options:nil];
            cell = [parts objectAtIndex:0];
        }
        cell.appoinmentID = [[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"AppointmentId"];
        cell.USER = [[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"UserId"];
        userID = cell.USER;
        cell.appoinmentstartTime =[[[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"DayTimeSlot"]valueForKey:@"StartTime"];
        cell.appoinmentendTime =[[[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"DayTimeSlot"]valueForKey:@"EndTime"];

        cell.cellImage.imageURL = url;

        cell.appoinmentTime.text = [NSString stringWithFormat:@"%@ - %@",[[[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"DayTimeSlot"]valueForKey:@"StartTime"], [[[detailsToShowTemp valueForKey:@"Appointment"]valueForKey:@"DayTimeSlot"]valueForKey:@"EndTime"]];

        cell.personName.text = [NSString stringWithFormat:@"%@ %@",FirstName,LastName];

        cell.appoinmentDate.text = dateText;
        return cell;
    }

    }


    return cell;

}

È stato utile?

Soluzione 2

Small change in the code you have written for cellForRowAtIndexPath

>>[cell setComingDateDel:self];  // Move this line to the if block

 if (! cell) 
 {
   NSArray *parts = [[NSBundle mainBundle] loadNibNamed:@"comingDayCell" owner:nil options:nil];
   cell = [parts objectAtIndex:0];
   [cell setComingDateDel:self]; // Now this is proper
  }

Altri suggerimenti

I think you forgot [cell setComingDateDel:self];

Add this calling in cellForRowAtIndexPath.

UPDATE:

Try to add [cell setComingDateDel:self]; right before you do return.

add button in CellForComingDates class and connect IBAction to the button, then

- (IBAction)DeleteButton:(id)sender {
    [self.comingDateDel DeleteButtonAction_new:self];
}

then after write your delete method in your .m which have tableview.

Inside cellForRowAtIndexPath delegate use this code:

[cell.deleteButton setTag:indexPath.row];
[cell.deleteButton addTarget:self 
                       action:@selector(deletebuttonClicked:)
            forControlEvents:UIControlEventTouchDown];

then

-(void)deletebuttonClicked:(UIButton*)button {

    long int selectedIndex=(long int)[button tag];
 }

Check below function by debugging:

- (IBAction)DeleteButton:(id)sender {
if ([self.comingDateDel respondsToSelector:@selector(DeleteButtonAction_new:)]) {
    [self.comingDateDel DeleteButtonAction_new:self];
}
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top