hey, Could any one guide me through this I have 开发者_JAVA技巧around 15 entries in table I would like another 15 to come up with the load more in last UITableViewCell. could anyone help me?
to show an extra row in the tableview, in
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return dataRows+1;
}
In
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//after setting tableviewcell
if(indexPath.row==dataRows){
cell.textLabel.text=@"Load More Rows";
}
}
In
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==dataRows){
//there you can write code to get next rows
}
}
You need to update the numberOfRows variable according to the displayed rows.
Edit: After fetching the extra entries, you can add them to the existing entries array using the following method. Your original array should be a NSMutableArray
to use this method.
[originalEntriesArray addObjectsFromArray:extraEntriesArray];
I wrote an example project that does just this. Download it from GitHub https://github.com/Abizern/PartialTable
I wrote something that might be helpful : https://github.com/nmondollot/NMPaginator
It encapsulates pagination, and works with pretty much any webservice using page and per_page parameters. It also features a UITableView with automatic fetching of next results as you scroll down.
hope this helps
I took an Mutable array and an integer variable and set the total count of the array to the integer variable
arr = [[NSMutableArray alloc]initWithObjects:@"Radix",@"Riki", nil]; dataRows = [arr count];
and then i set the number of rows in the sections as per the integer variable in the datasource method of the table
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. return dataRows+1; }
because you wanted an extra cell at the end.
Now its time to set the text of the table cell
- (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];
}
// 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;
}
now on the hit of the more cells cell you want extra cells right so just add your code inside the
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
method, means you have to do something like this
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if(indexPath.row == dataRows) { //code for exra cells please } }
Run your app to check this code out.
精彩评论