<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 閱讀(524) 評論(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无码专区在线播放中文| 国产中文字幕免费观看| 亚洲AV色吊丝无码| 亚洲成a人无码亚洲成www牛牛| 国产特黄特色的大片观看免费视频| 国产成人免费一区二区三区| 亚洲AV男人的天堂在线观看| 成人免费男女视频网站慢动作 | 国产精品V亚洲精品V日韩精品 | 欧美a级在线现免费观看| 亚洲免费黄色网址| 91免费国产在线观看| 国产.亚洲.欧洲在线| 在线jyzzjyzz免费视频| 亚洲高清国产AV拍精品青青草原| 精品一区二区三区免费视频 | 成年在线网站免费观看无广告| 亚洲一区二区三区精品视频| 我想看一级毛片免费的| 黄页视频在线观看免费| 国产亚洲精品成人a v小说| 中文成人久久久久影院免费观看| 亚洲va在线va天堂va不卡下载| 免费夜色污私人影院网站| 亚洲精品无码久久久久| 99在线热视频只有精品免费| 日韩亚洲人成在线| 免费一级毛片在级播放| 水蜜桃视频在线观看免费播放高清 | 亚洲视频免费在线观看| 免费做爰猛烈吃奶摸视频在线观看| 亚洲国产精品18久久久久久| 亚洲黄片毛片在线观看| 5g影院5g天天爽永久免费影院| 最新国产精品亚洲| 亚洲日韩精品一区二区三区| 又大又硬又粗又黄的视频免费看| 亚洲av激情无码专区在线播放| 欧洲精品成人免费视频在线观看 | 国产亚洲人成在线影院| 亚洲AV电影院在线观看|