Number of rows from tableview
I was working with the tableview and I want开发者_如何学运维ed the number of rows (i.e the number of items in tableview). How can I get the number of rows, if available?
Please help me out, thanks in advance.
take a instance variable in your header file.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
yourHeaderFileVariable = [noOfItemsInArray count];
NSLog(@"total item in table %d",yourHeaderFileVariable);
return [noOfItemsInArray count];
}
or try this
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section {
NSLog(@"total item in table %d",[noOfItemsInArray count]);
return [noOfItemsInArray count];
}
The number of rows in table view for a section is what you are returning from (NSInteger)tableView:numberOfRowsInSection:
. So if you return something like [mySource count]
from this method then the number of rows is [mySource count]
.
For example:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [data count];
}
// to get the count
NSInteger rowCount = [data count];
Now replace [data count]
with whatever calculation you have in the delegate method.
You need to implement the delegate method :
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [yourArray count];
}
You can then show the result in the table header by using the following delegate method :
- (NSString *)tableView:(UITableView *)resultTableView titleForHeaderInSection:(NSInteger)section
{
NSString *str=[NSString stringWithFormat:@"%i",[yourArray count]];
str=[str stringByAppendingString:@" matches"];
return str;
}
For example, if you have 7 results in the table, the header will display the text "7 matches"
- (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];
}
This function returns the number rows(items) in your tableview
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [listOfItems count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return numberOfRows;
}
精彩评论