我是iOS開發新手,我試圖在視圖中顯示用戶配置文件,同時我想讓用戶有可能通過點擊「編輯」按鈕來編輯他的配置文件。 UINavigationBar上的按鈕,如Apple網站上顯示的那樣:Enabling Edit Mode in a View Controller在ViewController中啓用編輯模式
我試圖找到一個解釋所有這些的教程,但我沒有找到任何東西。有人可以通過給我一個教程鏈接或示例代碼來幫助我嗎?
PS:我使用故事板。
非常感謝!
我是iOS開發新手,我試圖在視圖中顯示用戶配置文件,同時我想讓用戶有可能通過點擊「編輯」按鈕來編輯他的配置文件。 UINavigationBar上的按鈕,如Apple網站上顯示的那樣:Enabling Edit Mode in a View Controller在ViewController中啓用編輯模式
我試圖找到一個解釋所有這些的教程,但我沒有找到任何東西。有人可以通過給我一個教程鏈接或示例代碼來幫助我嗎?
PS:我使用故事板。
非常感謝!
的概念是相同的。您添加一個UIBarButtonItem並更改tableView的當前模式和buttonItem的狀態(文本),以顯示編輯短劃線和其他內容(如果您選擇)。
這裏是一個簡單的編輯模式按鈕按下將tableView發送到編輯模式,以便於刪除。你也可以
- (IBAction)editPressed:(id)sender
{
// If the tableView is editing, change the barButton title to Edit and change the style
if (_theTableView.isEditing) {
UIBarButtonItem *newButton = [[UIBarButtonItem alloc]initWithTitle:@"Edit" style:UIBarButtonSystemItemDone target:self action:@selector(editPressed:)];
self.navigationItem.rightBarButtonItem = newButton;
_buttonEdit = newButton;
[_theTableView setEditing:NO animated:YES];
}
// Else change it to Done style
else {
UIBarButtonItem *newButton = [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonSystemItemEdit target:self action:@selector(editPressed:)];
self.navigationItem.rightBarButtonItem = newButton;
_buttonEdit = newButton;
[_theTableView setEditing:YES animated:YES];
}
}
-(void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
// You could do other things in here based on whether editing is true or not
}
你可以在viewDidLoad裏設置默認的編輯按鈕給你navigationItem barbutton,如下圖所示。
-(void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
隨着蘋果文檔中給出
editButtonItem - 返回切換其編輯和完成之間的標題和相關的狀態欄按鈕的項目。默認的按鈕動作調用setEditing:animated:方法。
覆蓋setEditing:animated:在您的視圖控制器中,如下所示。
-(void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
}
您可以使用布爾變量編輯來達到您的要求。
對你非常有幫助,非常感謝你,現在我可以切換到編輯模式,但我仍然不知道如何將UITableView中顯示的信息顯示到UITextView中,如下所示: http://developer.apple.com /library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/EnablingEditModeinaViewController/EnablingEditModeinaViewController.html – raed 2013-05-08 18:46:48
非常感謝您的幫助,問題是我是iOS上的初學者,這些例子對我來說並不那麼清楚!我試圖瞭解他們並應用他們,如果我能做到的話,我會通知你。 – raed 2013-05-07 21:51:11
你有任何其他建議plz! – raed 2013-05-08 18:47:39
你需要指定你想要做什麼,並提出具體問題,否則你不會在這裏得到很多幫助。這是一個以非常快速和可靠的反應爲基礎的社區,但只有在問題非常具體且以前沒有提出時纔會這樣做。 Google是你的朋友,你可以在啓用編輯模式時找到大量資源。 – 2013-05-08 19:07:58