2015-06-20 2 views
1

У меня есть UITableViewCell, и внутри у меня есть UITextfield, я сделал 7 разделов (динамический), и каждый раздел имеет одну ячейку (одну строку), которая включает в себя UITextField.как включить свойство пользовательского взаимодействия UITextField внутри ячейки UITableView

Теперь у меня есть одна кнопка в правом верхнем углу UINavigationBar (кнопка EDIT). Мне нужно включить поддержку взаимодействия с пользователем для всех текстовых полей раздела. Это возможно?

Это мой UITableviewCode

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    sharedManager=[Mymanager sharedManager]; 
    return 1; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    //UITableViewCell *cell; 
    UILabel *label = nil; 
    NSString *text; 
    cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 
    if (cell == nil) 
    { 
     cell = [[timeLineDetailsCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"cell"]; 

     label = [[UILabel alloc] initWithFrame:CGRectZero]; 
     [label setLineBreakMode:UILineBreakModeWordWrap]; 
     [label setMinimumFontSize:FONT_SIZE]; 
     [label setNumberOfLines:0]; 
     [label setFont:[UIFont systemFontOfSize:FONT_SIZE]]; 
     [label setTag:1]; 

     [[label layer] setBorderWidth:2.0f]; 

     [[cell contentView] addSubview:label]; 

    } 

    if(indexPath.section==0){ 
     text = [contents objectAtIndex:0]; 
    }else if(indexPath.section==1){ 
     text = [contents objectAtIndex:1]; 
    }else if(indexPath.section==2){ 
     text = [contents objectAtIndex:2]; 
    }else if(indexPath.section==3){ 
     text = [contents objectAtIndex:3]; 
    }else if(indexPath.section==4){ 
     text = [contents objectAtIndex:4]; 
    }else if(indexPath.section==5){ 
     text = [contents objectAtIndex:5]; 
    }else if(indexPath.section==6){ 
     text = [contents objectAtIndex:6]; 
    }else if(indexPath.section==7){ 
     text = [contents objectAtIndex:7]; 
    } 

    CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f); 

    CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap]; 

    if (!label) 
     label = (UILabel*)[cell viewWithTag:1]; 

    [cell.ds1 setText:text]; 
    [cell.ds1 setFrame:CGRectMake(CELL_CONTENT_MARGIN, CELL_CONTENT_MARGIN, CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), MAX(size.height, 44.0f))]; 

    return cell; 

} 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; 
{ 
    NSString *text ; 
    if(indexPath.section==0){ 
     text = [contents objectAtIndex:0]; 
    }else if(indexPath.section==1){ 
     text = [contents objectAtIndex:1]; 
    }else if(indexPath.section==2){ 
     text = [contents objectAtIndex:2]; 
    }else if(indexPath.section==3){ 
     text = [contents objectAtIndex:3]; 
    }else if(indexPath.section==4){ 
     text = [contents objectAtIndex:4]; 
    }else if(indexPath.section==5){ 
     text = [contents objectAtIndex:5]; 
    }else if(indexPath.section==6){ 
     text = [contents objectAtIndex:6]; 
    }else if(indexPath.section==7){ 
     text = [contents objectAtIndex:7]; 
    } 


    CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f); 

    CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap]; 

    CGFloat height = MAX(size.height, 44.0f); 

    return height + (CELL_CONTENT_MARGIN * 2); 
} 

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{ 
    NSString *str= [title objectAtIndex:section]; 
    return str; 
} 

мой редактировать код кнопки

-(void)editTimeline{ 
    cell.ds1.userInteractionEnabled=YES; 
    [cell.ds1 setUserInteractionEnabled:TRUE]; 
    cell.ds1.layer.borderColor=[UIColor lightGrayColor].CGColor; 
    cell.ds1.layer.borderWidth=1; 
    // [cell.ds1 becomeFirstResponder]; 

} 

, когда я нажимаю на кнопку EDIT только некоторые строки имеют возможность редактировать .please помочь мне.

+0

на самом деле ' cell.ds1' обновляется каждый раз, когда создается или используется новая ячейка. поэтому только некоторые строки могут редактировать. 'cell.ds1' - это объект, который был добавлен в последнюю ячейку (новая или повторно используемая ячейка). –

+0

'if (indexPath.section == 0) { text = [contents objectAtIndex: 0];' - Что делать, если у вас есть 100 единиц вместо 7? –

ответ

0
define flag data memeber with Bool type 

-(void)editTimeline{ 
    flag=true; 
    [self.tableView reload]; 
} 


add following condition in cellForRowAtIndexpath method 


if(flag==true){ 
[cell.ds1 setUserInteractionEnabled:TRUE]; 
} 
else{ 
[cell.ds1 setUserInteractionEnabled:NO]; 
} 

let me know if it help u....!!! 
+0

спасибо, что правильно работает – bangalore

+0

Добро пожаловать ... !! @bangalore –

0

Я хотел бы использовать этот код -

NSArray *cellArray=[itemsTable visibleCells]; 
    for (UITableViewCell *aCell in cellArray) 
    { 
     UITextField *myTField=(UITextField*)yourtextField; 
     myTField.userInteractionEnabled=YES; 
    } 

myTField добавляется в клетку как подвид с определенным тегом. Вы можете получить myTField через [aCell viewWithTag:someTag];.

0

Вызов cellForRowAtIndexPath для каждой строки в вашем разделе, сделать его неактивен в Tableview (в противном случае он будет Тригером крана вместо вас) и включить взаимодействие пользователей в том, как вы хотите, чтобы вы вернулись ячейки: 3

Смежные вопросы