I have five fields setup on a Signup controller. Username, displayname, password, confirm password and email address.
They are setup with the following:
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];
}
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)")
Just call [self tableView:self.tableView cellForRowAtIndexPath:indexPath]
. It will return the cell at the given index path.
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];
}
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.