我从第一页的API解析数据并将其添加到中UITableView
,现在页面可以是多个,比如说100,我也可以从API获取页面总数。但是我将如何在tableView中为每个页面实现它并在滚动时显示指示器。看看我的代码
NSURL *theURL = [NSURL URLWithString:@"http://qa.networc.in:1336/api/dispatcher/rideScheduled/:1"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20.0f];
//Specify method of request(Get or Post)
[theRequest setHTTPMethod:@"GET"];
//Pass some default parameter(like content-type etc.)
[theRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[theRequest setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:token forHTTPHeaderField:@"x-access-token"];
NSURLResponse *theResponse = NULL;
NSError *theError = NULL;
NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&theResponse error:&theError];
if (responseData == nil)
{
return;
}
NSDictionary *dataDictionaryResponse = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&theError];
NSLog(@"url to send request= %@",theURL);
NSLog(@"%@",dataDictionaryResponse);
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:theRequest
completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error) {
NSLog(@"Response:%@ %@\n", response, error);
if(error == nil)
{
NSString * text = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog(@"Data = %@",text);
}
dictionary = [[NSJSONSerialization JSONObjectWithData:data options:0 error:nil]objectForKey:@"data"];
NSArray *total = [dictionary objectForKey:@"total"];
NSLog(@"latlop %@", total);
NSArray *IDArray = [dictionary objectForKey:@"docs"];
for (NSDictionary *Dict in IDArray)
{
NSMutableDictionary *temp = [NSMutableDictionary new];
[temp setObject:[Dict objectForKey:@"_id"] forKey:@"_id"];
NSLog(@"temp %@", temp );
NSString *booknumber = [Dict objectForKey:@"bookingNumber"];
if([booknumber length] != 0)
[temp setObject:booknumber forKey:@"bookingNumber"];
NSMutableDictionary *stp1 = [Dict objectForKey:@"stop1"];
if ([[stp1 allKeys] containsObject:@"address"]) {
[temp setObject:[stp1 objectForKey:@"address"] forKey:@"address"];
];
}
NSMutableDictionary *stp2 = [Dict objectForKey:@"stop2"];
if ([[stp2 allKeys] containsObject:@"address"]) {
[temp setObject:[stp2 objectForKey:@"address"] forKey:@"address1"];
NSArray *latlongstp2 = [stp2 objectForKey:@"location"];
[temp setObject:[latlongstp2 objectAtIndex:0] forKey:@"latitude"];
[temp setObject:[latlongstp2 objectAtIndex:1] forKey:@"longitude"];
}
NSMutableDictionary *currentloc = [Dict objectForKey:@"currentLocation"];
if ([[currentloc allKeys] containsObject:@"address"]) {
[temp setObject:[currentloc objectForKey:@"address"] forKey:@"address1"];
}
[getid addObject:temp];
}
if (getid.count>0)
{
[self updateTable];
}
}];
[task resume];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1; //count of section
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [getid count];
}
- (void)tableView:(UITableView *)tableView willDisplayCell: (UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == [getid count] - 1 ) {
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ScheduleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.BookingId.text = [[getid objectAtIndex:indexPath.row]objectForKey:@"_id"];
cell.BookingNo.text = [[getid objectAtIndex:indexPath.row]objectForKey:@"bookingNumber"];
cell.stop1.text = [[getid objectAtIndex:indexPath.row]objectForKey:@"address"];
cell.stop2.text = [[getid objectAtIndex:indexPath.row] objectForKey:@"address1"];
cell.Currentloc.text = [[getid objectAtIndex:indexPath.row] objectForKey:@"address"];
return cell;
}
有很多方法可以实现这一点,例如以下方法:
NSMutableArray
在TableView
Delegates和中加载的全局变量DataSaurce
。tableview
您可以根据您的API使用下一页URL再次调用它,并在每次调用时重新加载表格https://github.com/OpenFibers/DragRefreshAndLoadMoreTableDemo
https://github.com/Abizern/PartialTable
https://github.com/robertmryan/UITableView-Bottom-
Refresh
根据您的代码:
在.h类中
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
NSURL* nextURL;
int currentPage;
}
在.M类中
- (void)viewDidLoad {
currentPage = 1;
[self LoadData];
[super viewDidLoad];
}
-(void)LoadData
{
NSURL *theURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://qa.networc.in:1336/api/dispatcher/rideScheduled/:%d",currentPage]];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20.0f];
//Specify method of request(Get or Post)
[theRequest setHTTPMethod:@"GET"];
//Pass some default parameter(like content-type etc.)
[theRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[theRequest setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:token forHTTPHeaderField:@"x-access-token"];
NSURLResponse *theResponse = NULL;
NSError *theError = NULL;
NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&theResponse error:&theError];
if (responseData == nil)
{
return;
}
NSDictionary *dataDictionaryResponse = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&theError];
NSLog(@"url to send request= %@",theURL);
NSLog(@"%@",dataDictionaryResponse);
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:theRequest
completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error) {
NSLog(@"Response:%@ %@\n", response, error);
if(error == nil)
{
NSString * text = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog(@"Data = %@",text);
}
currentPage ++;
dictionary = [[NSJSONSerialization JSONObjectWithData:data options:0 error:nil]objectForKey:@"data"];
NSArray *total = [dictionary objectForKey:@"total"];
NSLog(@"latlop %@", total);
[getid addObjectsFromArray:total];
[self updateTable];
}];
[task resume];
}
我创建了这个部分标题,不幸的是,我不知道如何在右边添加一些填充。 这是我的密码:
我对目标C和iOS有点新手,所以我的问题可能很愚蠢:)我在调试模式下检查了self.table数据,那里没有空项,并且返回正确的值。下面是UITableView数据源方法: 以下是我得到的: 在模拟器:http://take.ms/rm2DL 视图层次结构:http://take.ms/oALdi 这个空白区域正好有超过20个点的高度,所以我假设它应该是某种奇怪的标题。
我有一个elasticsearch请求如下: 我想在这个请求中添加分页,就像 我搜索了很多,找到了一个关于它的链接:https://github.com/elastic/elasticsearch/issues/4915. 但我仍然没有得到实现方法。 有没有办法通过Elasticsearch本身而不是我的应用程序来实现它?
问题内容: 如何在Swift中的tableView单元中以编程方式嵌入?我就是那样做 问题答案: 这是您可以在单元格上嵌入的方法。 这是切换调用贝克方法 @LeoDabus 。 注意:如果您可能有多个,则应创建一个CustomCell子类并配置您的内部 方法而不是表视图方法。当将可重用的队列释放出队列时,将其投射到您的CustomCell中这是@LeoDabus的示例
问题内容: 我有这个日期对象: d1的值为 现在,我想在上述日期增加10分钟。 更改的价值, 但应该是。 它可以正确地增加分钟,但它也会更改月份,不知道为什么! 问题答案: 您遇到的问题是您正在使用。您应该使用。是一个月,几分钟。试试看 其他方法: 它可以像这样简单(其他选择是使用joda- time )
问题内容: 我正在使用ElasticSearch 1.5.2,希望具有以下设置: 我应该在哪里添加它们?我的意思是在创建索引之前还是之后? 通过在线搜索,我发现了一些类似的方法 但是我有2个问题, 我收到编译错误:ImmutableSettings.builder类型的方法loadFromSource不适用于参数XContentBuilder 另外,我不知道如何将我的设置转换为这种格式。在哪里可以