Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在PFQueryTableView编辑模式下添加新的插入行?_Ios_Objective C_Uitableview_Parse Platform - Fatal编程技术网

Ios 如何在PFQueryTableView编辑模式下添加新的插入行?

Ios 如何在PFQueryTableView编辑模式下添加新的插入行?,ios,objective-c,uitableview,parse-platform,Ios,Objective C,Uitableview,Parse Platform,我想知道如何在PFQueryTableView中添加新的插入行。我的表视图工作正常,可以正确加载所有PFObject。但是,我想在表视图底部添加一个新行,这样当我单击该行时,它将弹出另一个视图控制器来创建一个新的PFObject。由于PFQueryTableViewController附带了其编辑按钮,该按钮仅允许删除PFObject。你能帮我吗 视图内加载 在-表视图中:行数部分: In-tableView:cellForRowAtIndexPath:对象: 按照您描述的方式进行操作的问题是没

我想知道如何在
PFQueryTableView
中添加新的插入行。我的表视图工作正常,可以正确加载所有PFObject。但是,我想在表视图底部添加一个新行,这样当我单击该行时,它将弹出另一个视图控制器来创建一个新的
PFObject
。由于
PFQueryTableViewController
附带了其
编辑按钮
,该按钮仅允许删除PFObject。你能帮我吗

视图内加载

在-表视图中:行数部分:

In-tableView:cellForRowAtIndexPath:对象:


按照您描述的方式进行操作的问题是没有相应的
PFObject
传递到
tableView:cellForRowAtIndexPath:object:
方法。这可能会导致问题。此外,用户必须滚动到底部才能访问添加按钮

一个更好的方法(我也是这样做的,因为我的应用程序就是这样做的)就是在导航栏上添加另一个按钮

viewDidLoad
或自定义
init
方法中:

// Make a new "+" button
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addButtonPressed)];
NSArray *barButtons = [NSArray arrayWithObjects:self.editButtonItem,addButton,nil];
self.navigationItem.rightBarButtonItems = barButtons;
// The user pressed the add button
MyCustomController *controller = [[MyCustomController alloc] init];
[self.navigationController pushViewController:controller animated:YES];
// Replace this with your view controller that handles PFObject creation
- (void) setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
    if(editing)
    {
        UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addButtonPressed)];
        // self.editButtonItem turns into a "Done" button automatically, so keep it there
        NSArray *barButtons = [NSArray arrayWithObjects:self.editButtonItem,addButton,nil];
        self.navigationItem.rightBarButtonItems = barButtons;
    }
    else
        self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
然后在
addButtonPressed
方法中:

// Make a new "+" button
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addButtonPressed)];
NSArray *barButtons = [NSArray arrayWithObjects:self.editButtonItem,addButton,nil];
self.navigationItem.rightBarButtonItems = barButtons;
// The user pressed the add button
MyCustomController *controller = [[MyCustomController alloc] init];
[self.navigationController pushViewController:controller animated:YES];
// Replace this with your view controller that handles PFObject creation
- (void) setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
    if(editing)
    {
        UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addButtonPressed)];
        // self.editButtonItem turns into a "Done" button automatically, so keep it there
        NSArray *barButtons = [NSArray arrayWithObjects:self.editButtonItem,addButton,nil];
        self.navigationItem.rightBarButtonItems = barButtons;
    }
    else
        self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
如果您只希望用户能够在编辑模式下创建新对象,请将逻辑移到
setEditing:animated:
方法:

// Make a new "+" button
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addButtonPressed)];
NSArray *barButtons = [NSArray arrayWithObjects:self.editButtonItem,addButton,nil];
self.navigationItem.rightBarButtonItems = barButtons;
// The user pressed the add button
MyCustomController *controller = [[MyCustomController alloc] init];
[self.navigationController pushViewController:controller animated:YES];
// Replace this with your view controller that handles PFObject creation
- (void) setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
    if(editing)
    {
        UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addButtonPressed)];
        // self.editButtonItem turns into a "Done" button automatically, so keep it there
        NSArray *barButtons = [NSArray arrayWithObjects:self.editButtonItem,addButton,nil];
        self.navigationItem.rightBarButtonItems = barButtons;
    }
    else
        self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
希望有帮助!这是我做这件事的方式(某种程度上),在我看来,这比在tableView底部的单元格内有一个按钮要干净一些