开发者

how to i set 'no records found' in UITableView

开发者 https://www.devze.com 2023-02-22 14:47 出处:网络
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 cellFo

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消