你能帮我加载更多UITableView
吗?我使用加载更多方法,但所有记录都返回而不是 25。代码有什么问题?请帮助:S 感谢您的回复
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad{
itemArray = [[NSMutableArray alloc] init];
[self ServiseBaglan];}
- (void)ServiseBaglan{
NSString *soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<SOAP-ENV:Envelope \n"
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n"
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
"xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"\n"
"SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" \n"
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> \n"
"<SOAP-ENV:Body> \n"
"<OnemliYer xmlns=\"http://tempuri.org/\">\n"
"<station>%@</station>\n"
"<dilId>%@</dilId>\n"
"</OnemliYer> \n"
"</SOAP-ENV:Body> \n"
"</SOAP-ENV:Envelope>\n", izmir , @"1"];
NSURL *url = [NSURL URLWithString:@"http://www.manavgatportal.com/Service1.svc"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://tempuri.org/IService1/OnemliYer" forHTTPHeaderField:@"Soapaction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
// NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
NSURLConnection *theConnection = [[NSURLConnection alloc]initWithRequest:theRequest delegate:self];
if(theConnection) {
// webData = [[NSMutableData data] retain];
webData = [[NSMutableData data]init];
}
else {
NSLog(@"theConnection is NULL");
}
[self.tableView reloadData];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath
*)indexPath{
return 40;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:
(NSInteger)section
{
if ([itemArray count] >= 25) {
count= [itemArray count] + 1;
NSLog(@": %d", count);
}else
{
count=[itemArray count];
NSLog(@": %d", count);
}
return count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
static NSString *CellIdentifier2 = @"Cell2";
static NSInteger TitleTag = 2;
static NSInteger AddresseTag = 1;
UITableViewCell *cell;
if (indexPath.row != [itemArray count] ) {
cell= (UITableViewCell *) [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier];
}
NSDictionary *Item = [itemArray objectAtIndex:indexPath.row];
UIFont *font = [UIFont fontWithName:@"Arial" size:14];
cell.textLabel.font = font;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.detailTextLabel.numberOfLines = 2;
cell.textLabel.text = [Item objectForKey:@"a:Ad"];
cell.detailTextLabel.text = [Item objectForKey:@"a:Ilce"];
[[cell textLabel] setBackgroundColor:[UIColor clearColor]];
[[cell detailTextLabel] setBackgroundColor:[UIColor clearColor]];
}
else {
if(indexPath.row == count-1)
{
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2];
}
UILabel *loadMore =[[UILabel alloc]initWithFrame: CGRectMake(0,0,320,30)];
loadMore.textColor = [UIColor blackColor];
loadMore.highlightedTextColor = [UIColor darkGrayColor];
loadMore.backgroundColor = [UIColor clearColor];
loadMore.font=[UIFont fontWithName:@"Verdana" size:14];
loadMore.textAlignment=UITextAlignmentCenter;
loadMore.font=[UIFont boldSystemFontOfSize:14];
loadMore.text=@"load More...";
[cell addSubview:loadMore];
}
}
return cell;
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
[self.tableView reloadData];
}