I create a custom table view cell.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITextField *editField=nil;
...
NSString *CellIdentifier = [NSString stringWithFormat:@"cell:%d",indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
// Configure the cell...
switch (indexPath.row) {
case 0:
{
cell.textLabel.text=DEVNAME_TEXT_NDVC;
cell.textLabel.font=[UIFont boldSystemFontOfSize:LABEL_TEXTSIZE_NDVC];
editField=[[UITextField alloc] initWithFrame:CGRectMake(158, 9, cell.frame.size.width-183, cell.frame.size.height-15) ];
editField.tag=DEVNAME_TAG_NDVC;
...
[cell.contentView addSubview:editField ];
[editField release];
}
break;
The table has 5 lines only, and each of them is on the screen always. Later, when I try to get access to the cell I always get 'nil'
The following code should place cursor to apropriate UITextField when user tap the cell, but it doesn't, since 'cell' is always =0.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [NSString stringWithFormat:@"cell:%d",indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UITextField *tf=nil;
[tableView deselectRowAtIndexPath: indexPath animated: YES];
[activeField resignFirstResponder]; // Last used UITextField
switch (indexPath.row) {
case 0: //
tf=(UITextField*)[cell.contentView viewWithTag:DEVNAME_TAG_NDVC];
[tf becomeFirstResponder]; // Show the keyboard
//[tf performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0.7];
break;
Please, could you suggest what is wrong? Why [tableView dequeueReusableCellWithIdentifier:CellIdentifier] always =0,
but all of the table cells are always visible.
Thanks.
Maybe I don't understand the question, but don't table cells only become reusable once they are no longer being displayed? If they are still visible, how could you reuse them?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With