Pergunta

Eu estou usando seguinte método no meu aplicativo:

- (UITableViewCell *)tableView:(UITableView *)tblView cellForRowAtIndexPath:(NSIndexPath *)indexPath

Neste método, usando indexPath.row posso obter o número da linha de cada linha.

Mas eu quero realmente acessar a célula em que fileira e fazer alguma formatação em que a célula única.

Por favor me orientar.

Foi útil?

Solução

Talvez haja um mal-entendido. O método que você está citando é suposto dizer o tableView qual linha para exibir em que indexPath. Assim, sempre que o tableView pede este método, ele faz isso porque não há nenhuma linha neste indexPath ainda.

O código do modelo irá gerar uma nova célula ou um dequeue:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

     static NSString *CellIdentifier = @"Cell";

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     if (cell == nil) {
              cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
     }

Você pode então cell acesso para configurar o conteúdo de cada célula ou adicionar conteúdo ao contentView.

Se você manipular a formatação de uma célula em uma base por linha (por exemplo, a cor do cell.textLabel), você deve fazer isso no seguinte método delegado:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

Outras dicas

Enquanto as outras respostas irá funcionar bem, mas vai apenas mudar a célula que o usuário bateu no. Para o meu caso eu queria mudar as outras células também. Depois de procurar por aí, eu tentei:

[[tableView cellForRowAtIndexPath:5 setAccessoryType:UITableViewCellAccessoryNone];

isso não funciona, porque IndexPath não é um inteiro. (Indexpath.row é, no entanto). Assim, ao olhar o doc, eu descobri que podemos usar NSIndexPath para codificar uma linha em valor NSIndexPath. Aqui está o código de trabalho:

[[tableView cellForRowAtIndexPath: [NSIndexPath indexPathForRow:5 inSection:0]] setAccessoryType:UITableViewCellAccessoryNone];

Desta forma, você pode acessar a qualquer lugar celular, A QUALQUER ROW / SECTION, desde que tenha o objeto tableview.

Espero que isso ajude alguém.

Você pode acessar a visível de células usando o método UITableView -cellForRowAtIndexPath. De UITableView referência:

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath

Valor de retorno
Um objeto representando um célula da tabela ou nulo se a célula não é visível ou indexPath está fora de range.

No entanto (IMO) cellForRowAtIndexPath é o melhor lugar para uma configuração de célula.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top