我想實現一個非常類似於Mobile Safari中的書籤視圖的列表。當您單擊編輯,你會得到如下:如何實現可編輯的UITableView,類似於Safari書籤?
從這個屏幕,你可以刪除一個項目,並更改其屬性(通過右側的DisclosureIndicator)。我跟着Xamarin的tutorial,但我無法弄清楚如何在表格處於編輯模式時如何添加DisclosureIndicator。我將採用ObjC或C#解決方案。
我在這裏錯過了一些簡單的東西嗎?
我想實現一個非常類似於Mobile Safari中的書籤視圖的列表。當您單擊編輯,你會得到如下:如何實現可編輯的UITableView,類似於Safari書籤?
從這個屏幕,你可以刪除一個項目,並更改其屬性(通過右側的DisclosureIndicator)。我跟着Xamarin的tutorial,但我無法弄清楚如何在表格處於編輯模式時如何添加DisclosureIndicator。我將採用ObjC或C#解決方案。
我在這裏錯過了一些簡單的東西嗎?
在iOS中,這是通過以下方法來完成:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete;
}
- (void) setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing: editing animated: animated];
[self.tableView setEditing:editing animated:animated];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//delete rows
}
}
公開指示器是電池附件。你可以在cellForRowAtIndexPath
方法中設置它。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
使用
cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
在GetCell方法
我可能失去了一些東西,但我把UITableView的進入編輯模式的那一刻,DisclosureIndicator消失。 – AngryHacker