Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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
Iphone tableview中的行数_Iphone_Objective C_Uitableview - Fatal编程技术网

Iphone tableview中的行数

Iphone tableview中的行数,iphone,objective-c,uitableview,Iphone,Objective C,Uitableview,我使用的是tableview,我想要的是行数(即tableview中的项目数)。如何获取行数(如果可用) 请帮帮我, 提前感谢。此函数返回tableview中的行数(项目) - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return numberOfRows; } - (NSInteger)tableView:(UITable

我使用的是tableview,我想要的是行数(即tableview中的项目数)。如何获取行数(如果可用)

请帮帮我,
提前感谢。

此函数返回tableview中的行数(项目)

  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {



        return numberOfRows;
    }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [listOfItems count];
  }

节的表视图中的行数是您从
(NSInteger)表视图:numberOfRowsInSection:
返回的行数。因此,如果从该方法返回类似于
[mySource count]
的内容,则行数为
[mySource count]

例如:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [data count];
}

// to get the count 
NSInteger rowCount = [data count];

现在用委托方法中的任何计算替换
[data count]

在头文件中取一个实例变量

 - (NSInteger)tableView:(UITableView *)tablefirst numberOfRowsInSection:(NSInteger)section {

int count; 
    count=0;
     count=[*your array name* count]; 
    NSLog(@"row count=%d",count);
return [*your array name* count];
    }
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section      {
     yourHeaderFileVariable = [noOfItemsInArray count];
     NSLog(@"total item in table %d",yourHeaderFileVariable);
     return [noOfItemsInArray count];
}
或者试试这个

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:    (NSInteger)section      {

     NSLog(@"total item in table %d",[noOfItemsInArray count]);
     return [noOfItemsInArray count];
}

您需要实现委托方法:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section  
{  
return [yourArray count];  
}  
- (NSString *)tableView:(UITableView *)resultTableView titleForHeaderInSection:(NSInteger)section  
{  
    NSString *str=[NSString stringWithFormat:@"%i",[yourArray count]];  
    str=[str stringByAppendingString:@" matches"];  
    return str;  
}  
然后,可以使用以下委托方法在表格标题中显示结果:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section  
{  
return [yourArray count];  
}  
- (NSString *)tableView:(UITableView *)resultTableView titleForHeaderInSection:(NSInteger)section  
{  
    NSString *str=[NSString stringWithFormat:@"%i",[yourArray count]];  
    str=[str stringByAppendingString:@" matches"];  
    return str;  
}  

例如,如果表中有7个结果,则标题将显示文本“7个匹配”

您已在numberOfRowsinSection中设置了行数,因此您已经知道。我希望变量中包含数字,以便我可以在控制台上打印它rowCount=“任意”u表示NSInteger*rowCount=“array list”int count;计数=0;count=[您的数组名count];NSLog(@“行计数=%d”,计数);如何获取变量中的计数,以便在console@RahulVyas:嘿,谢谢,但是如何在NSInteger变量中获取变量noOfItemsInArray.simple NSInteger count=[yourArray count]//注意:yourArray引用的是NSArray/NSMutableArray的对象。如果调用[yourArray count]方法,如果希望查看该方法返回的内容,则该方法将返回一个NSInteger。请参阅NSArray/NSMutableArrayhey的文档。我执行了此NSInteger count=[arrName count];NSLog(@“整数%d中的项目”,计数);但我无法在控制台上打印noofrows方法中的断点,并查看数组是否已初始化。@Rahul Vyas:嘿,它已初始化,我在尝试NSLog(@“表%d中的总项,[arrName count])时得到了该值;返回[arrName count];