Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.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 xCode-POST请求、JSON返回、TableCells_Ios_Json_Connection_Tableview - Fatal编程技术网

iOS xCode-POST请求、JSON返回、TableCells

iOS xCode-POST请求、JSON返回、TableCells,ios,json,connection,tableview,Ios,Json,Connection,Tableview,我的处境如下:我有一排信标。我有一个php脚本,它根据发送到该脚本的信标的主次值返回JSON对象 当我只有一个信标时,我的代码工作得很好,因为只有一个请求。现在的问题是,实际上应该发生以下情况: Request > Return JSON > Parse > Save in Array > Request (final)...Read out values in Tablecell. 这里有谁能帮助我确保下一个请求只有在前一个请求被正确处理并添加到我的ObjectArr

我的处境如下:我有一排信标。我有一个
php
脚本,它根据发送到该脚本的信标的主次值返回
JSON
对象

当我只有一个信标时,我的代码工作得很好,因为只有一个请求。现在的问题是,实际上应该发生以下情况:

Request > Return JSON > Parse > Save in Array > Request (final)...Read out values in Tablecell.
这里有谁能帮助我确保下一个请求只有在前一个请求被正确处理并添加到我的ObjectArray之后才能被发送

因为现在我的第二个请求总是返回(
null
)结果。(JSON中没有错误,因为hordcoded确实有效)

以下是我的一些代码:

建立联系:

for (int i = 0; i < self.beacons.count; i++) {
    if (self.beacons.count == 0) {
        NSLog(@"No beacons");
    }
    else {
        CLBeacon *beacon = (CLBeacon *)[self.beacons objectAtIndex:i];

        NSLog(@"Make beacon");
        self.majorValue = beacon.major;
        self.minorValue = beacon.minor;
        NSLog(@"beacon: MAJOR: %@. MINOR: %@", self.majorValue, self.minorValue);

        NSLog(@"Make Request");
        NSString *post = [NSString stringWithFormat:@"minor=%@&major=%@", self.minorValue, self.majorValue]; //POST naar php die returnd adhv deze waarden
        NSLog(@"REQUEST MWITHMAJOR: %@, EN MINOR %@: ", self.majorValue,  self.minorValue);

        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];
        NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];

        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://uploads.genicus.be/ruben/API/ArtworkData.php"]];
        [request setHTTPMethod:@"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        [request setHTTPBody:postData];

        NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    }
}
}

制作我的桌子:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
myTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; //we willen de costumcell gebruiken en niet de standaard UItableCell

if (cell == nil) {
    cell = [[myTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

Artwork *artwork = (Artwork *)[self.savingBeaconSpecs objectAtIndex:indexPath.row];
NSLog(@"indexPath.row %ld", (long)indexPath.row);

NSLog(@"LOG ARTWORK IN TABLECELL%@", artwork);

cell.ArtworkTitle.text = artwork.title;
cell.ArtworkCreator.text = artwork.artist;
cell.ArtworkCategory.text = artwork.categorie;
cell.ArtworkYear.text = artwork.CreationYear;

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@", artwork.image]];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:imageData];
cell.ArtworkImage.image = image;

return cell;
}

因此,确切的问题是:在
connectiondFinishLoading
中记录
ArtWorkArray
时,在第一个请求之后的所有请求都会导致(
null
)。第二个对象已生成,但实际上是空的


日志的屏幕截图:

您使用的
self.data
是否为
[NSJSONSerialization JSONObjectWithData:self.data选项:0错误:&err]
来自?-(void)连接:(NSURLConnection*)连接didReceiverResponse:(nsurResponse*)响应{//NSLog(@“什么是响应:%@”,响应);}-(void)连接:(NSURLConnection*)连接didReceiveData:(NSData*)数据{//NSLog(@“Did Received Data!”);[self.Data appendData:theData];//NSLog(@“Received Data:%@”,theData);}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
myTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; //we willen de costumcell gebruiken en niet de standaard UItableCell

if (cell == nil) {
    cell = [[myTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

Artwork *artwork = (Artwork *)[self.savingBeaconSpecs objectAtIndex:indexPath.row];
NSLog(@"indexPath.row %ld", (long)indexPath.row);

NSLog(@"LOG ARTWORK IN TABLECELL%@", artwork);

cell.ArtworkTitle.text = artwork.title;
cell.ArtworkCreator.text = artwork.artist;
cell.ArtworkCategory.text = artwork.categorie;
cell.ArtworkYear.text = artwork.CreationYear;

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@", artwork.image]];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:imageData];
cell.ArtworkImage.image = image;

return cell;