Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 拉式刷新功能不是';行不通_Ios_Objective C - Fatal编程技术网

Ios 拉式刷新功能不是';行不通

Ios 拉式刷新功能不是';行不通,ios,objective-c,Ios,Objective C,我已经把下面的代码放进去了,看起来很接近,但我不明白为什么它没有进行实际的刷新。它有“Pull to refresh”和正确显示更新的文本,但它没有更新实际数据。我是错过了一些明显的东西,还是我把它放错地方了 我编辑以添加self tableview调用以重新加载数据。还是不走运 下面的最终编辑用户通过调用数据提要解决了这个问题 - (void)viewDidLoad { [super viewDidLoad]; UIRefreshControl *refresh = [[UIRefreshC

我已经把下面的代码放进去了,看起来很接近,但我不明白为什么它没有进行实际的刷新。它有“Pull to refresh”和正确显示更新的文本,但它没有更新实际数据。我是错过了一些明显的东西,还是我把它放错地方了

我编辑以添加self tableview调用以重新加载数据。还是不走运

下面的最终编辑用户通过调用数据提要解决了这个问题

- (void)viewDidLoad
{
[super viewDidLoad];

UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to refresh"];
[refresh addTarget:self action:@selector(refreshmytable:)   forControlEvents:UIControlEventValueChanged];
self.refreshControl = refresh;

NSURLSessionConfiguration *config =
[NSURLSessionConfiguration defaultSessionConfiguration];

_session = [NSURLSession sessionWithConfiguration:config
                                         delegate:self
            //   delegate:nil
                                    delegateQueue:nil];

[self fetchFeed];



}

- (void)refreshmytable:(UIRefreshControl *)refreshControl{

[self fetchFeed]; //Added 12:12 9.16.14
refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Updating"];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMM d, h:mm a"];
NSString *updated = [NSString stringWithFormat:@" Last Update: %@", [formatter     stringFromDate:[NSDate date]]];
refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:updated];
                                  [refreshControl endRefreshing];

[self.tableView reloadData]; //Added this 11:32 9.16.14

}





- (void)fetchFeed
{
 NSString *userEID = MAP_getUsername();
 //NSLog(userEID);

 NSString *requestString1 = [@"URL" stringByAppendingString:userEID];

 NSString *requestString2 = @"&status=pending";

 NSString *requestString = [requestString1 stringByAppendingString:requestString2];

 //NSLog(requestString);

 /*NSString *requestString = @"http://URL";
*/
NSURL *url = [NSURL URLWithString:requestString];
NSURLRequest *req = [NSURLRequest requestWithURL:url];

NSURLSessionDataTask *dataTask =
[self.session dataTaskWithRequest:req
                completionHandler:
 ^(NSData *data, NSURLResponse *response, NSError *error) {


     NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:data
                                                                options:0
                                                                 error:nil];
     self.changeList = jsonObject[@"List"];
     //self.changeList=nil; //tried to add here to remove duplicate data

     NSLog(@"%@", self.changeList);

     //- add code here to populate BNRItemStore with the change order list.
     // - following code should be rewritten in fetchFeed that will load BNRItemStore.
     if (self.changeList.count>0) {
         for (int i = 0; i < self.changeList.count; i++) {
             NSDictionary *coItem = self.changeList[i];

             [[BNRItemStore sharedStore]
              addItemWithApproverEid:coItem[@"approverEid"]
              assignmentGroup:coItem[@"assignmentGroup"]
              changeOrder:coItem[@"changeOrder"]
              subcategory:coItem[@"subCatagory"]
              title:coItem[@"title"]


              ];
         }
     }
     //NSLog(@"sizeof(NSInteger) = %@", @(sizeof(NSInteger)));
     //- end comment

     dispatch_async(dispatch_get_main_queue(), ^{
        [self.tableView reloadData];
     });
     //self.changeList=nil; //trying to null out list for refresh non duplicate data


   //  NSString *json = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
   //  NSLog(@"%@", json);
 }];


[dataTask resume];
}
-(void)viewDidLoad
{
[超级视图下载];
UIRefreshControl*刷新=[[UIRefreshControl alloc]init];
refresh.attributedTitle=[[NSAttributedString alloc]initWithString:@“拉入刷新”];
[refresh addTarget:self action:@selector(refreshmytable:)forControlEvents:UIControlEventValueChanged];
self.refreshControl=刷新;
NSURLSessionConfiguration*配置=
[NSURLSessionConfiguration默认会话配置];
_session=[NSURLSession sessionWithConfiguration:config
代表:赛尔夫
//代表:无
委派队列:无];
[自取馈送];
}
-(void)refreshmytable:(UIRefreshControl*)refreshControl{
[self-fetchFeed];//添加12:12 9.16.14
refreshControl.attributedTitle=[[NSAttributedString alloc]initWithString:@“更新”];
NSDateFormatter*格式化程序=[[NSDateFormatter alloc]init];
[格式化程序setDateFormat:@“mmmd,h:mma”];
NSString*updated=[NSString stringWithFormat:@“上次更新:%@],[stringFromDate:[NSDate date]]格式化程序字符串;
refreshControl.attributedTitle=[[NSAttributedString alloc]initWithString:updated];
[刷新控制结束刷新];
[self.tableView reloadData];//添加了这个11:32 9.16.14
}
-(void)fetchFeed
{
NSString*userEID=MAP_getUsername();
//NSLog(userEID);
NSString*requestString1=[@“URL”stringByAppendingString:userEID];
NSString*requestString2=@“&status=pending”;
NSString*requestString=[requestString1 stringByAppendingString:requestString2];
//NSLog(请求字符串);
/*NSString*requestString=@”http://URL";
*/
NSURL*url=[NSURL URLWithString:requestString];
NSURLRequest*req=[nsurlRequestRequestWithURL:url];
NSURLSessionDataTask*数据任务=
[self.session datatask with request:req
completionHandler:
^(NSData*数据,NSURLResponse*响应,NSError*错误){
NSDictionary*jsonObject=[NSJSONSerialization jsonObject WithData:data
选项:0
错误:无];
self.changeList=jsonObject[@“List”];
//self.changeList=nil;//试图在此处添加以删除重复数据
NSLog(@“%@”,自我变更列表);
//-在此处添加代码以使用变更单列表填充BNRItemStore。
//-应在将加载BNRItemStore的fetchFeed中重写以下代码。
如果(self.changeList.count>0){
for(int i=0;i
您需要在
refreshmytable
方法中的某个地方调用
reloadData
,以便表视图更新数据

- (void)refreshmytable:(UIRefreshControl *)refreshControl{
    refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Updating"];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"MMM d, h:mm a"];
    NSString *updated = [NSString stringWithFormat:@" Last Update: %@", [formatter     stringFromDate:[NSDate date]]];
    refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:updated];
                              [refreshControl endRefreshing];
    [self.tableView reloadData]

}您没有获取新数据。您有一个在
viewDidLoad
中调用的方法/消息调用
fetchFeed
,但从未在刷新方法/消息中调用它。我假设如果刷新,则需要获取新数据。调用“[self fetchFeed];”在重新加载表视图之前。如果要异步获取数据,则在获取新数据完成时,需要在完成块中重新加载表视图。

refreshmytable:方法中的哪个代码正在收集新数据并告诉表使用它进行更新?我添加了上面的编辑。但还是没有运气。它看起来像是在运行,但数据仍然保持不变。@JamesCockerham,在填充新数据之前,请确保将保存提要的数据结构设置为nil。此外,如果答案有帮助并回答了您的问题,请将其标记为正确答案。如果你问别人而不确认答案,人们不会帮你。谢谢你的帮助。从逻辑上讲,我应该将数据集的nil放在哪里?在成功获取feed之后,在将获取的feed添加到数组或任何要将其添加到的数据结构之前,您可以将其放在fetchFeed方法中。刚刚意识到,现在我得到的是重复数据。“你能告诉我我是否把它放在上面了吗?”JamesCockerham,见原始帖子中的评论。