Accessing cell attributes outside of cellForRowAtIndexPath

后端 未结 5 1270
既然无缘
既然无缘 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];
    }
    
    0 讨论(0)
  • 2021-01-18 10:13

    Updated Swift,

    let cell = tableView.cellForRow(at: indexPath) as! <Insert tableviewcell Controller here>
    

    Then you can access all the objects inside your cell the same way as when you are in cellforrowat

    let displayname = cell.labelfordisplayname.text!
    print("This is the displayname -> \(displayname)")
    
    0 讨论(0)
  • 2021-01-18 10:19

    Just call [self tableView:self.tableView cellForRowAtIndexPath:indexPath]. It will return the cell at the given index path.

    0 讨论(0)
  • 2021-01-18 10:25

    Access Custom Label In UiTableView "didselectRow"

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    UILabel *label = (UILabel*)[cell viewWithTag:101]; // you can get label like
    label.backgroundColor=[UIColor redColor];
    

    Get index path from button

    - (void) cellEditAction:(UIButton *)sender {
    
      CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:FriendsTable];
    NSIndexPath *indexPath = [FriendsTable indexPathForRowAtPoint:buttonPosition];
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    UILabel *label = (UILabel*)[cell viewWithTag:101]; // you can get label like
    label.backgroundColor=[UIColor redColor];
    
    }
    
    0 讨论(0)
  • 2021-01-18 10:27

    you can get UITableViewCell using NSIndexPath.

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:YOUR_ROW inSection:YOUR_SECTION];
    
    UITableViewCell* cell = [yourTable cellForRowAtIndexPath:indexPath];
    cell.textLabel.textColor = YOUR_COLOR;
    [yourTable reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    

    Hope it helps you.

    0 讨论(0)
提交回复
热议问题