<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Neil的備忘錄

    just do it
    posts - 66, comments - 8, trackbacks - 0, articles - 0

    Iphone開發 可編輯表格

    Posted on 2010-10-04 15:53 Neil's NoteBook 閱讀(525) 評論(0)  編輯  收藏 所屬分類: Iphone Development

    In some of the iPhone's default apps, you may find that you can "edit" a table, then have little red minus signs appear to the left of the table, giving you the option to delete those rows. So, how do you do that in your own programs?

    The answers, it turns out, is a very simple one:

    [self.tableView setEditing:YES animated:YES];

    That's literally all you need to do to set up those deletion marks. Then you just need to respond to tableView:commitEditingStyle: forRowAtIndexPath:.

    However, there are some nuances, particularly the questions of how you start up a table's editing and how you end it, and I'm going to show some real-world examples of those methods over the course of this article ...

    An Actual Example

    The program that I've showed off elsewhere in this series makes uses of a tableView's editing functionality by allowing the user to delete characters from the app, each of whom are represented by a table row

    First, you need to set up some way to activate the functionality:

    - (void)editCharacters {
        [self.tableView setEditing:YES animated:YES];
        UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]
            initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                                               target:self
                                               action:@selector(endTableEditing)];
        self.navigationItem.leftBarButtonItem = doneButton;
        [doneButton release];

        self.navigationItem.rightBarButtonItem = nil;
    }

    This method is triggered when a user selects an "Edit" button. You'll note that besides starting the editing, I also change around the button in my navbar. That's because when a user is editing I no longer need an "Edit" button, but instead require a "Done" button. You might alternatively set buttons' enabled properties to NO ... but in any case, you always need to give users a way to get out of editing mode.

    Your tableView: method will probably delete the table item from your table and/or the data store that it originates from:

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

        if (editingStyle == UITableViewCellEditingStyleDelete) {
            [self recordWasDeleted:indexPath.row];
        }
    }

    For completeness state, I'll also include the method call generated when the "Done" button is clicked:

    - (void)endTableEditing {
        [self.tableView setEditing:NO animated:YES];
        [self updateButtons];
    }

    This is pretty much the opposite of my editCharacters method: the editing is turned back off, then the buttons are returned to their original state.

    And that's really all you need to do to edit a table: turn editing on, respond to the deletion message, and turn it back off at the end.

    Doing More with Table Edits

    You do have some other editing possibilities that I'm not going to cover in depth in this article. Most notably, you can adjust the editingStyle property of any individual cell. Apple claims it's set to UITableViewCellEditingStyleNone by default, but it sure looks to me like it's set to UITableViewCellEditingStyleDelete, which is what shows those handsome red minus marks. If you instead want to insert rows, you can set it to UITableViewCellEditingStyleInsert, and then do the appropriate thing when tableView:commitEditingStyle:forRowAtIndexPath: receives input of type insert.

    That's it for me and tables for the nonce. If there's any other topics that you'd like covered regarding them, let me know in the comments. In the meantime, I'm planning to next return to my splashView topic, as some folks have requested in comments.

    主站蜘蛛池模板: 日产久久强奸免费的看| 亚洲中文字幕久久无码| 四虎影库久免费视频| 亚洲AV成人潮喷综合网| 亚洲国产精品13p| 精品亚洲综合久久中文字幕| 亚洲精品成人久久| 亚洲精品第一国产综合亚AV| 久久久久久噜噜精品免费直播| 黄色网站软件app在线观看免费| 久久精品免费电影| 中文字幕无码免费久久99| 女人18毛片水最多免费观看| 亚洲色一色噜一噜噜噜| 亚洲一区二区免费视频| 国产久爱免费精品视频| 亚洲色欲久久久综合网东京热| 亚洲依依成人精品| 男女一边摸一边做爽的免费视频| 国产亚洲精品成人AA片新蒲金 | 久久一区二区三区免费播放| 在线观看的免费网站| 久久夜色精品国产噜噜亚洲a| 中文字幕在线成人免费看| 黄色网址免费大全| 精品国产亚洲男女在线线电影| 亚洲精品第一综合99久久| 国产成人3p视频免费观看| 亚洲精品熟女国产| 免费理论片51人人看电影| 亚洲电影在线免费观看| 四虎影视大全免费入口| 亚洲高清免费视频| 免费看小12萝裸体视频国产| 9久热精品免费观看视频| 亚洲免费在线视频| 三级黄色片免费看| 亚洲乱码无限2021芒果| 免费一级毛片免费播放| 青娱乐在线视频免费观看| 欧洲精品免费一区二区三区|