嗨,当我通过单击加载更多单元格来显示表格记录时,我遇到了问题。问题是,当我单击加载更多单元格时,表格必须再加载两条记录,然后加载更多文本必须向前移动,例如,第一次在第三个单元格的表格上加载 2 条记录是当我单击此单元格时加载更多单元格然后另外两条记录必须加载到表中,并且此加载更多文本移动到第 5 个单元格。但在我的情况下,问题是当我单击在第三个位置加载更多单元格时,它也会移动到第五个位置,但在第三个单元格记录不加载并且加载更多文本出现在第三个单元格上。请告诉我如何处理这个问题这是代码
#import "RootViewController.h"
#import "XMLAppDelegate.h"
#import "song.h"
#import "BookDetailViewController.h"
@implementation RootViewController
@synthesize mylabel,mylabel1,mylabel2,spinner,cell;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if([myarray count]>pageSize)
{
return pageSize+1;
}
return myarray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 75;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
song *asong = [appDelegate.artists objectAtIndex:indexPath.row];
NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:[myarray objectAtIndex:indexPath.row ]]];
UIImage *image=[UIImage imageWithData:data];
if(indexPath.row<pageSize)
{
UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(5, 10, 60, 60)];
imageView.image=image;
[cell addSubview:imageView];
CGRect CellFrame1 = CGRectMake(65, 10, 220, 45);
mylabel1 = [[UILabel alloc] initWithFrame:CellFrame1];
mylabel1.text = asong.title;
mylabel1.font = [UIFont boldSystemFontOfSize:12];
mylabel1.textColor = [UIColor blackColor];
[cell.contentView addSubview:mylabel1];
CGRect CellFrame2 = CGRectMake(65, 47, 150, 25);
mylabel2 = [[UILabel alloc] initWithFrame:CellFrame2];
mylabel2.text = asong.artist;
mylabel2.font = [UIFont systemFontOfSize:12];
[cell.contentView addSubview:mylabel2];
CGRect CellFrame = CGRectMake(255, 3, 60, 7);
mylabel = [[UILabel alloc] initWithFrame:CellFrame];
mylabel.text = asong.duration;
mylabel.textColor = [UIColor blueColor];
mylabel.font = [UIFont boldSystemFontOfSize:10];
[cell.contentView addSubview:mylabel];
}
else
{
cell.textLabel.text = @"load more";
spinner = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
cell.accessoryView = spinner;
[spinner startAnimating];
[spinner performSelector:@selector(stopAnimating) withObject:nil afterDelay:1]; [spinner release];
}
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic -- create and push a new view controller
if (indexPath.row==pageSize)
{
pageSize=pageSize+2;
[cell reloadInputViews];
[tableView reloadData];
}
/* else if(bdvController == nil)
bdvController = [[BookDetailViewController alloc] initWithNibName:@"BookDetailView" bundle:[NSBundle mainBundle]];
song *asong = [appDelegate.artists objectAtIndex:indexPath.row];
bdvController.aartist = asong;
[self.navigationController pushViewController:bdvController animated:YES];*/
}
- (void)viewDidLoad {
[super viewDidLoad];
pageSize =2;
// Uncomment the following line to add the Edit button to the navigation bar.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
myarray = [[NSMutableArray alloc] initWithObjects:@"http://api.androidhive.info/music/images/adele.png",@"http://api.androidhive.info/music/images/eminem.png",@"http://api.androidhive.info/music/images/mj.png",@"http://api.androidhive.info/music/images/rihanna.png",@"http://api.androidhive.info/music/images/arrehman.png",@"http://api.androidhive.info/music/images/alexi_murdoch.png",@"http://api.androidhive.info/music/images/dido.png",@"http://api.androidhive.info/music/images/enrique.png",@"http://api.androidhive.info/music/images/ennio.png",@"http://api.androidhive.info/music/images/backstreet_boys.png",@"http://api.androidhive.info/music/images/adele.png",@"http://api.androidhive.info/music/images/eminem.png",@"http://api.androidhive.info/music/images/mj.png",@"http://api.androidhive.info/music/images/rihanna.png",@"http://api.androidhive.info/music/images/arrehman.png",@"http://api.androidhive.info/music/images/alexi_murdoch.png",@"http://api.androidhive.info/music/images/dido.png",@"http://api.androidhive.info/music/images/enrique.png",@"http://api.androidhive.info/music/images/ennio.png",@"http://api.androidhive.info/music/images/backstreet_boys.png",@"http://api.androidhive.info/music/images/adele.png",@"http://api.androidhive.info/music/images/eminem.png",@"http://api.androidhive.info/music/images/mj.png",@"http://api.androidhive.info/music/images/rihanna.png",@"http://api.androidhive.info/music/images/arrehman.png",@"http://api.androidhive.info/music/images/alexi_murdoch.png",@"http://api.androidhive.info/music/images/dido.png",@"http://api.androidhive.info/music/images/enrique.png",@"http://api.androidhive.info/music/images/ennio.png",@"http://api.androidhive.info/music/images/backstreet_boys.png", nil];
appDelegate = (XMLAppDelegate *)[[UIApplication sharedApplication] delegate];
self.title = @"Songs";
}
/*
// Override to support editing the list
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
}
if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support conditional editing of the list
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support rearranging the list
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/
/*
// Override to support conditional rearranging of the list
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
/*
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
*/
/*
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
}
*/
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[bdvController release];
[appDelegate release];
[super dealloc];
}
@end