Accessing cell attributes outside of cellForRowAtIndexPath

后端 未结 5 1268
既然无缘
既然无缘 2021-01-18 09:56

I have five fields setup on a Signup controller. Username, displayname, password, confirm password and email address.

They are setup with the following:



        
5条回答
  •  心在旅途
    2021-01-18 10:10

    You can create by using tags.

    in cellForRowAtIndexPath

    static NSString *cellId = @"Cell";
    CustomCell *cell = (CustomCell *)[self.tblView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {
        NSArray * myNib;
        myNib =[[NSBundle mainBundle]loadNibNamed:@"CustomCell" owner:self options:nil];
        cell = (CustomCell *)[myNib lastObject];
    }
    [cell.deleteBtn addTarget:self action:@selector(cellDeleteAction:) forControlEvents:UIControlEventTouchUpInside];
    cell.deleteBtn.tag = indexPath.row;
    [cell.editBtn addTarget:self action:@selector(cellEditAction:) forControlEvents:UIControlEventTouchUpInside];
    cell.editBtn.tag = indexPath.row;
    

    after that you can create button action method like this,

    - (void) cellEditAction:(UIButton *)sender {
    UIButton *button = (UIButton *)sender;
    NSString *rateId = [[resDict valueForKey:@"value"]objectAtIndex:button.tag];
    }
    

提交回复
热议问题