开发者

What's SimpleEditableListAppDelegate?

I'm trying to follow the TableView programming guide, and I'm copying the code directly from the guide, but I get "SimpleEditableListAppDelegate unde开发者_如何学JAVAclared" when I try to compile. Google returns nothing but the programming guide. What's SimpleEditableListAppDelegate, and how do I use it?


SimpleEditableListAppDelegate is the delegate of the application. It's a class that is automatically created when you make a new Xcode project. The reason why your code isn't compiling is because a SimpleEditableListAppDelegate class does not exist in your project, because your project is named differently from the one in the table view programming guide. The "SimpleEditableListAppDelegate undeclared" error appears because somewhere in the code there is a reference to that class which doesn't exist.

You should be able to see the name of your app delegate class in the files sidebar in Xcode, so just wherever you see SimpleEditableListAppDelegate replace it with your actual delegate class name. Either that, or replace all instances of SimpleEditableListAppDelegate with [[UIApplication sharedApplication] delegate].

It sounds like you need to understand the basics of iPhone programming first, so you might want to take a look at this.


I think it's safe to say we are all looking at this source from Apple...

- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    // If row is deleted, remove it from the list.
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        SimpleEditableListAppDelegate *controller = (SimpleEditableListAppDelegate *)[[UIApplication sharedApplication] delegate];
        [controller removeObjectFromListAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
}

SimpleEditableListAppDelegate is just a name of their example class. In YOUR code you just want to use the name of the delegate for your table view (i.e. MyAppDelegate) or just using "[self removeObjectFromListAtIndex];" instead of creating controller worked just fine for me.

removeObjectFromListAtIndex is again just an arbitrary name for a function you would create to delete the contents of the array that supports your table view data. I didn't use a function, instead I just used a few lines of code.

Here is how it worked for me...

 if (editingStyle == UITableViewCellEditingStyleDelete) {
  // Update Model
  NSMutableArray *work_array = [NSMutableArray arrayWithArray:self.city_table];
  [work_array removeObjectAtIndex:indexPath.row];
  self.city_table = [NSArray arrayWithArray:work_array];
  [[NSUserDefaults standardUserDefaults] setObject:self.city_table forKey:KEY_CITY_TABLE];

  // Update View
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  }

I hope this helps... Z@K!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜