看起来这是一个简单的任务。在工具栏(键盘顶部)内的按钮应该发送发送者到一个函数。使用下面的代码,我在调试器中收到“向实例发送未识别的选择器”的错误信息。
我的目标是访问自定义单元格的特定TextField。这段代码对于识别例如开关非常有效。
工具栏的声明:
UIToolbar* itemToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
itemToolbar.barStyle = UIBarStyleBlackTranslucent;
itemToolbar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelNumberPad)],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:@"Save" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)],
nil];
[itemToolbar sizeToFit];
doneWithNumberPad的功能:
- (void)doneWithNumberPad:(id)sender {
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSLog(@"%@", [object valueForKey:@"item"]);
}
感谢您的任何帮助。
- (void)doneWithNumberPad:(id)sender
更改为- (void)doneWithNumberPad:(UIBarButtonItem *)button
来执行相同操作。现在不需要进行类型转换。有关Objective-C中类型转换的更多阅读,请参见casting in Objective-C。 - AnupdasconvertPoint:toView:
只在UIView
的子类中可用。如果您使用视图创建UIBarButtonItem
,则可以完成此操作。 - Anupdas