【问题标题】:How to delete a row from table in watchkit in objective c如何从目标c的watchkit中的表中删除一行
【发布时间】:2016-04-12 10:47:58
【问题描述】:

我正在开发一个 watchkit 应用程序,我有一个表视图,它必须具有删除行的功能。我看到了一个使用内容菜单的教程。但不知道如何从表中删除行。请帮帮我。

    #import "HomeInterfaceController.h"
#import "HomeTableRowController.h"
#import "DetailHomeInterfaceController.h"

@interface HomeInterfaceController ()
@property (unsafe_unretained, nonatomic) IBOutlet WKInterfaceTable *homeTable;
@property (nonatomic,strong) NSArray *nameArr;

@end

@implementation HomeInterfaceController

- (void)awakeWithContext:(id)context {
    [super awakeWithContext:context];
    self.nameArr = [NSArray arrayWithObjects: @"Jill Valentine", @"Peter Griffin", @"Meg Griffin", @"Jack Lolwut",
                    @"Mike Roflcoptor", @"Cindy Woods", @"Jessica Windmill", @"Alexander The Great",
                    @"Sarah Peterson", @"Scott Scottland", @"Geoff Fanta", @"Amanda Pope", @"Michael Meyers",
                    @"Richard Biggus", @"Montey Python", @"Mike Wut", @"Fake Person", @"Chair",
                    nil];
    [self setupTable];

    // Configure interface objects here.
}

- (void)willActivate {
    // This method is called when watch view controller is about to be visible to user
    [super willActivate];
}

- (void)didDeactivate {
    // This method is called when watch view controller is no longer visible
    [super didDeactivate];
}

- (void)setupTable {

    [self.homeTable setNumberOfRows:[self.nameArr count] withRowType:@"HomeTableRowController"];

    for (NSInteger i = 0; i < self.nameArr.count; i++)
    {

        HomeTableRowController *row = [self.homeTable rowControllerAtIndex:i];
        NSString *thisBook = [self.nameArr objectAtIndex:i];

        [row.reminderHeadlineLabel setText:thisBook];
       // [row.imageRow setImage:[UIImage imageNamed:@"abc.jpg"]];

    }


}

- (void)table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex
{
   NSDictionary *d=[NSDictionary dictionaryWithObject:@"hi" forKey:@"nm"];
    [self presentControllerWithName:@"DetailHome" context:d];
}
- (IBAction)deleteButtonAction {
}

@end

【问题讨论】:

  • 你能添加你已经完成的代码并更具体吗?
  • 我没有做太多@Shrolox
  • 首先尝试用单元格实现表格视图,然后如果您显示代码和特定问题,也许社区将能够帮助您。有很多关于在 objC 中创建 tableview 的教程。例如这里:swiftiostutorials.com/watchkit-tutorial
  • Shrolox 我已经实现了这个,我现在正在寻找如何删除行...
  • 哦,对不起,我误解了你:/你能发布你的代码,以便我调整我的答案吗?

标签: objective-c iphone xcode7 watchkit


【解决方案1】:

你需要在你的deleteButtonAction函数中调用removeRowsAtIndexes

// first create an index set with the index of the row you want to delete
NSIndexSet *indexes = [[NSIndexSet alloc] initWithIndex:index];
// then call the function
[self.homeTable removeRowsAtIndexes:indexes];

docs有更多信息

【讨论】:

  • 谢谢....有没有办法通过上下文菜单删除行...。我的意思是我有一个上下文菜单添加到我有一个表格视图的控制器中,所以可以这样做是吗??
  • 我认为您可以使用上下文菜单的“标签”属性来存储行的索引。但由于它特定于上下文菜单,也许你应该发布一个关于它的新问题
  • 当然我会发布它,请帮助我提供您宝贵的代码:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多