tags:

views:

59

answers:

2

Hi everyone

I am wondering, I have an empty table and I want to display a text in that table, then I want to clear that text when the table has been inserted with something else. And the text will appear again when I completely remove everything in the table again.?

+1  A: 

In your dataSource for your UITableView there is a method:

-tableView:objectValueForTableColumn:row:

In that method you can check your NSArray or whatever you have supplying data to your table to see if there are any entries. If there are none and the request is for row zero, column zero, just return your 'no data' string.

To clarify syntax, assume you have an NSArray named songs which you wish to print:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    //boilerplate cell production
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];

    //check if we have data to supply, if not set message to "No Songs Available"
    //otherwise print the name of the song in each cell
    if (indexPath.row == 0 && indexPath.section == 0 && [songs count] == 0)
        cell.textLabel.text = @"No Songs Available";
    else if (indexPath.row < [songs count])
        cell.textLabel.text = [(Song *)[songs objectAtIndex:indexPath.row] songName];

    return cell;
}
bmalicoat
Thanks for your reply. But I would like to know the syntax, i am quite confused about the syntax in objective C. I am actually still abeginner
Le Anh Tai
Here's a good resource for Objective-C syntax: http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html
Chuck
A: 

Thanks a lot for your help. It help me a lot. This is some of my simple code for that matter earlier. I could run it, but if you see there is a better way, please go ahead suggest me.

if (sender == artistMenuButton) { [mainAppDelegate xitiWithS2:7 p:@"Favoris_Artistes"]; [songBackButton setHidden:YES]; [artistBackButton setHidden:(0==artistBackButtonToClick)]; selectedMenuIndex = 1; if ([mainDataCenter.favoriteSongArray count] == 0) {

  [label setTextColor:[UIColor whiteColor]];
  [label setText:@"AUCUN FAVORI DE FICHE ARTISTE"];
 }
 else
 {
  [label setHidden:YES];
 }

}
Rocker