2011-05-28 9 views
12

hey, Podría alguien guiarme a través de esto Tengo alrededor de 15 entradas en la tabla Me gustaría que otras 15 subieran con la carga más en la última UITableViewCell. ¿Alguien podría ayudarme?haciendo un botón "cargar más" en uitableviewcell?

+2

posible duplicado de ["Cargar más" en UITableView] (http://stackoverflow.com/questions/4410257/) o [Cómo implementar "Cargar 25 más"] (http://stackoverflow.com/questions/ 2801069 /) o [Aplicación de correo cargar más mensajes] (http://stackoverflow.com/questions/4396464/) o [Cargar más registros en iPhone] (http://stackoverflow.com/questions/4965919/) o [Agregar cargar más opciones a la vista de tabla] (http://stackoverflow.com/questions/5898399/) entre [otros] (http://stackoverflow.com/search?q=iphone+load+more) –

Respuesta

19

para mostrar una fila adicional en el tableview, en

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return dataRows+1; 
    } 

En

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

     //after setting tableviewcell 

     if(indexPath.row==dataRows){ 

     [email protected]"Load More Rows"; 
     } 
    } 

En

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 

    if(indexPath.row==dataRows){ 
    //there you can write code to get next rows 
    } 
} 

Es necesario actualizar los numberOfRows variable en función de las filas que se muestran.

Editar: Después de obtener las entradas adicionales, puede agregarlas a la matriz de entradas existentes utilizando el siguiente método. Su matriz original debe ser NSMutableArray para usar este método.

[originalEntriesArray addObjectsFromArray:extraEntriesArray];

+0

@SriPriya, Agregar esto línea 'numberOfRows = [yourEntriesArray count] + 1;' para hacerlo más claro. – EmptyStack

+0

@Simon: hola ..., actualicé el código – SriPriya

+0

@SriPriya, Hmmm :) – EmptyStack

1

esperanza esto ayuda

Me tomó una serie mutable y una variable entera y establezca el recuento total de la matriz a la variable entera

 
arr = [[NSMutableArray alloc]initWithObjects:@"Radix",@"Riki", nil]; 
dataRows = [arr count]; 

y luego me puse el número de filas en las secciones según la variable entera en el método de fuente de datos de la tabla

 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return dataRows+1; 
} 

porque quería una celda extra al final.

Ahora es el momento para ajustar el texto de la celda de la tabla

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

{ NSString estática * CellIdentifier = @ "Cell";

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

// Configure the cell... 

//setting the text of the cell as per Mutable array 
if (indexPath.row < [arr count]) { 

    cell.textLabel.text = [arr objectAtIndex:indexPath.row]; 
} 

//setting the text of the extra cell 

if (indexPath.row == dataRows) { 
    cell.textLabel.text = @"more cells"; 
}  
return cell; 

}

ahora en el éxito de la célula más celdas que desee células adicionales a la derecha por lo que acaba de añadir su código dentro del método

 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

, significa que tiene que hacer algo como esto

 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(indexPath.row == dataRows) 
    { 
     //code for exra cells please 
    } 
} 

Ejecute su aplicación para verificar este código.

4

escribí algo que podría ser útil: https://github.com/nmondollot/NMPaginator

Se encapsula la paginación, y funciona con casi cualquier servicio web utilizando la página y los parámetros per_page. También presenta una UITableView con búsqueda automática de los próximos resultados a medida que se desplaza hacia abajo.

Cuestiones relacionadas