Hi,
Using the following code I have been able to display a text message when there is no data to display in a uitableView:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
myAppDelegate *appDelegate = (myAppDelegate *)[[UIApplication sharedApplication] delegate];
if ([appDelegate.myDataArray count] == 0)
{
return 3;
}
return [appDelegate.myDataArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* myCellIdentifier = @"MyCell";
myAppDelegate *appDelegate = (myAppDelegate *)[[UIApplication sharedApplication] delegate];
if ([appDelegate.myDataArray count] == 0)
{
if (indexPath.row == 2)
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:myCellIdentifier]; // only reuse this type of cell here
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myCellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text = (@"No Records Found");
return cell;
}
else
{
// return a blank row for spacing
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:myCellIdentifier]; // only reuse this type of cell here
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myCellIdentifier] autorelease];
}
cell.textLabel.text = (@"");
return cell;
}
} ........
My problem is that I want to have this behaviour when I have deleted the records of a table using the method:
- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath {
Currently, the result is a crash when I delete the last record: "...The number of rows contained in an existing section after the update (3) must be equal to the number of rows contained in that section before the update (1)..."
Any ideas of how I can have the text displayed 3 rows down (as shown above) and not crash after I remove the last record while deleting?
Thanks.