how to i set 'no records found' in UITableView
I am parsing xml and placing it in a table vi开发者_运维技巧ew.... However when there are no records the table view is just blank. I tried counting the array where the records are stored in the cellForRowAtIndexPath
but It doesn't run this method when no records show so i cannot insert. Where can i set this...?
Thanks
Look at the method
numberOfRowsInSection:
Let's say you're using an array to populate your tableView, called dataArray
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([dataArray count] == 0) return 1;
return [dataArray count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if ([dataArray count] == 0) {
cell.textLabel.text = @"No Records Found";
} else {
cell.textLabel.text = [dataArray objectAtIndex:indexPath.row];
}
return cell;
}
In the numberOfRowsInSection u can put this.. it will work.
精彩评论