Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.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
Objective c 检测最后一行并添加一行_Objective C_Xcode_Ios5 - Fatal编程技术网

Objective c 检测最后一行并添加一行

Objective c 检测最后一行并添加一行,objective-c,xcode,ios5,Objective C,Xcode,Ios5,在我的应用程序中,我显示项目的。我的JSONfeed包含50个项目,但首先我想显示25个项目,当用户向下滚动到最后一行时,需要加载更多项目 我正在做: 下载JSONfeed NSString *jsonString = [NSString stringWithContentsOfURL:[NSURL URLWithString:xmlDataUrl] encoding:NSStringEncodi

在我的应用程序中,我显示项目的。我的
JSON
feed包含50个项目,但首先我想显示25个项目,当用户向下滚动到最后一行时,需要加载更多项目

我正在做:

下载
JSON
feed

NSString *jsonString = [NSString 
                        stringWithContentsOfURL:[NSURL URLWithString:xmlDataUrl] 
                        encoding:NSStringEncodingConversionAllowLossy
                        error:nil];
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *results = [parser objectWithString:jsonString error:nil];
parser = nil;
[self setTableData:[results objectForKey:@"feed"]];
//

//

并检测最后一行:

   if(indexPath.row == [self.tableData count] - 1) 
    {

        NSLog(@"Last Row");
    }
但它没有检测到最后一行。这是因为它下载的JSON包含超过25行吗

如何添加新行类似于
[self.tableDate count]+1可能吗


如果我返回
[tableData count]它正在检测最后一行,但行已被100%填充我需要显示25/50和+1

第二个代码块在哪里?是否在表委托的willDisplayCell:方法中

在我的一个项目中,我有非常相似的代码

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == self.search.count && [tableView.indexPathsForVisibleRows containsObject:indexPath])
    {
        [self.search findMoreStuff];
    }
}

在为self.search创建的行之后附加一行,因此在我的示例中,我正在检查self.search.count,但您可能希望查看self.search.count-1

您将无法添加行,因为您硬编码25作为节中的行数。我可以这样做<代码>返回[tableData count]但它将下载并显示所有项目,我可以设置最大值和更高的+1吗?第二块代码是什么意思?“最后一排”部分?抱歉,我指的是if(indexPath.row==[self.tableData count]-1)行。必须在willDisplayCell中调用的:
   if(indexPath.row == [self.tableData count] - 1) 
    {

        NSLog(@"Last Row");
    }
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == self.search.count && [tableView.indexPathsForVisibleRows containsObject:indexPath])
    {
        [self.search findMoreStuff];
    }
}