Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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 如果用户在UITableview中编辑UITextfield,则获取indexpath_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 如果用户在UITableview中编辑UITextfield,则获取indexpath

Ios 如果用户在UITableview中编辑UITextfield,则获取indexpath,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我使用的是UITableview如下图所示。如果我输入单价和数量,我需要计算。但是现在我不知道如何为UITableView中的两个文本框获取indexpath。在UITableView中,如果按钮单击转到didSelectRowAtIndexPath方法。在“数量”和“单价”文本框中键入时,不调用相同的方法 InvoiceMainViewController.h #import <UIKit/UIKit.h> #import <QuartzCore/Quart

我使用的是
UITableview
如下图所示。如果我输入单价和数量,我需要计算。但是现在我不知道如何为
UITableView
中的两个文本框获取indexpath。在
UITableView
中,如果按钮单击转到
didSelectRowAtIndexPath
方法。在“数量”和“单价”文本框中键入时,不调用相同的方法

InvoiceMainViewController.h

    #import <UIKit/UIKit.h>
    #import <QuartzCore/QuartzCore.h>

    @class InvoiceGridViewController;

    @protocol InvoiceTableCellProtocoll <NSObject>
    -(void) didPressButton:(InvoiceGridViewController *)theCell; 
    @end

    @interface InvoiceGridViewController : UITableViewCell {
             id<InvoiceTableCellProtocoll> delegationListener; }

    @property (nonatomic,assign) id<InvoiceTableCellProtocoll>  delegationListener;
    @property (nonatomic,retain) IBOutlet UITextField *invoiceItem;
    @property (nonatomic,retain) IBOutlet UITextField *invoiceUnitPrice;
    @property (nonatomic,retain) IBOutlet UITextField *invoiceQty;
    @property (nonatomic,retain) IBOutlet UITextField *invoiceTaxRate; 

    @property (nonatomic,retain) IBOutlet UILabel *invoiceItemId;
    @property (nonatomic,retain) IBOutlet UILabel *invoiceCurrencyId;
    @property (nonatomic,retain) IBOutlet UILabel *invoiceTaxRateId;

    @property (nonatomic,retain) IBOutlet UILabel *totalItemTax; @property
    @property (nonatomic,retain) IBOutlet UILabel *converstionMessage;

    -(IBAction)deleteSel:(id)sender;
    -(void)delFileSel; 
    @end
#导入
#进口
@类InvoiceGridViewController;
@协议InvoiceTableCellProtocoll
-(void)按下单元格中的按钮:(InvoiceGridViewController*);
@结束
@接口InvoiceGridViewController:UITableViewCell{
id delegationListener;}
@属性(非原子,赋值)id delegationListener;
@属性(非原子,保留)IBOutlet UITextField*invoiceItem;
@属性(非原子,保留)IBOutlet UITextField*发票单价;
@属性(非原子,保留)IBOutlet UITextField*发票数量;
@属性(非原子,保留)IBOutlet UITextField*发票税率;
@属性(非原子,保留)IBUILabel*invoiceItemId;
@属性(非原子,保留)IBOutlet UILabel*invoiceCurrencyId;
@属性(非原子,保留)IBUILabel*invoiceTaxRateId;
@财产(非原子,保留)IBUILabel*totalItemTax@财产
@属性(非原子,保留)IBUILabel*ConversationMessage;
-(iAction)deleteSel:(id)发送方;
-(无效)delFileSel;
@结束
InvoiceMainViewController.m

#import <UIKit/UIKit.h>
#import "SBPickerSelector.h"
#import <Foundation/Foundation.h>
#import "AFHTTPRequestOperationManager.h"
#import "AFURLResponseSerialization.h"
#import "AFURLRequestSerialization.h"
#import "InvoiceGridViewController.h"


@interface InvoiceMainViewController : UIViewController<UITableViewDataSource, UITableViewDelegate,NSXMLParserDelegate,UITextFieldDelegate,InvoiceTableCellProtocoll>{
#导入
#导入“SBPickerSelector.h”
#进口
#导入“AFHTTPRequestOperationManager.h”
#导入“AFURLResponseSerialization.h”
#导入“AFURLRequestSerialization.h”
#导入“InvoiceGridViewController.h”
@接口InvoiceMainViewController:UIViewController{

在textfield委托方法中,您可以获取行的indexpath,也可以直接获取textfields文本

-(void)textFieldDidEndEditing:(UITextField *)textField
{
CGPoint hitPoint = [txtfield convertPoint:CGPointZero toView:tbl];
hitIndex = [tbl indexPathForRowAtPoint:hitPoint];
int localCount = [txtfield.text intValue];
}

在textfield委托方法中,您可以获取行的indexpath,也可以直接获取textfield文本

-(void)textFieldDidEndEditing:(UITextField *)textField
{
CGPoint hitPoint = [txtfield convertPoint:CGPointZero toView:tbl];
hitIndex = [tbl indexPathForRowAtPoint:hitPoint];
int localCount = [txtfield.text intValue];
}

在textfield委托方法中,您可以获取行的indexpath,也可以直接获取textfield文本

-(void)textFieldDidEndEditing:(UITextField *)textField
{
CGPoint hitPoint = [txtfield convertPoint:CGPointZero toView:tbl];
hitIndex = [tbl indexPathForRowAtPoint:hitPoint];
int localCount = [txtfield.text intValue];
}

在textfield委托方法中,您可以获取行的indexpath,也可以直接获取textfield文本

-(void)textFieldDidEndEditing:(UITextField *)textField
{
CGPoint hitPoint = [txtfield convertPoint:CGPointZero toView:tbl];
hitIndex = [tbl indexPathForRowAtPoint:hitPoint];
int localCount = [txtfield.text intValue];
}

UITableViewCell
s创建子类。使用
cellName:(UITableViewCell*)cellName didSelectItem:(Item*)Item
等方法为每个单元格创建一个
协议

UITableViewCell
中,将
UITextView
委托设置为
self
,并实现
协议
textField应返回:
方法,将指示用户何时键入,因此在内部调用
[self.delegate cellName:self-didEditText:textField.text]

在您的
main视图控制器
表格视图中:cellforrowatinexpath:
设置
UITabelViewCell
的委托,并实施
协议


因此,当用户独立于表格行号输入任何文本字段时,您将在
MainViewController
中知道。

UITableViewCell
s进行子类化。使用
cellName:(UITableViewCell*)cellName didSelectItem:(Item*)等方法为每个单元格创建一个
protocol
项目
。您可以找到更多信息

UITableViewCell
中,将
UITextView
委托设置为
self
,并实现
协议
textField应返回:
方法,将指示用户何时键入,因此在内部调用
[self.delegate cellName:self-didEditText:textField.text]

在您的
main视图控制器
表格视图中:cellforrowatinexpath:
设置
UITabelViewCell
的委托,并实施
协议


因此,当用户独立于表格行号输入任何文本字段时,您将在
MainViewController
中知道。

UITableViewCell
s进行子类化。使用
cellName:(UITableViewCell*)cellName didSelectItem:(Item*)等方法为每个单元格创建一个
protocol
项目
。您可以找到更多信息

UITableViewCell
中,将
UITextView
委托设置为
self
,并实现
协议
textField应返回:
方法,将指示用户何时键入,因此在内部调用
[self.delegate cellName:self-didEditText:textField.text]

在您的
main视图控制器
表格视图中:cellforrowatinexpath:
设置
UITabelViewCell
的委托,并实施
协议


因此,当用户独立于表格行号输入任何文本字段时,您将在
MainViewController
中知道。

UITableViewCell
s进行子类化。使用
cellName:(UITableViewCell*)cellName didSelectItem:(Item*)等方法为每个单元格创建一个
protocol
项目
。您可以找到更多信息

UITableViewCell
中,将
UITextView
委托设置为
self
,并实现
协议
textField应返回:
方法,将指示用户何时键入,因此在内部调用
[self.delegate cellName:self-didEditText:textField.text]

在您的
main视图控制器
表格视图中:cellforrowatinexpath:
设置
UITabelViewCell
的委托,并实施
协议


因此,在
MainViewController
中,当用户独立于表格行号输入任何文本字段时,您就会知道。您可以通过各种方法来实现这一点

类型-1

2型

你可以得到你接触过的细胞

 CGPoint touchPoint = [sender convertPoint:CGPointZero toView: yourtableName];
NSIndexPath *clickedButtonIndexPath = [mainTable indexPathForRowAtPoint: yourtableName];
类型-3

类型-4

范例

如果您需要更多信息,请点击此处
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad 
{
   [super viewDidLoad];
   firstTxt.delegate = self;
   secondTxt.delegate = self;
  // Do any additional setup after loading the view, typically from a   nib.
 }

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
NSLog(@"textFieldShouldBeginEditing");
textField.backgroundColor = [UIColor colorWithRed:220.0f/255.0f    green:220.0f/255.0f blue:220.0f/255.0f alpha:1.0f];
return YES;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField{
NSLog(@"textFieldDidBeginEditing");
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
NSLog(@"textFieldShouldEndEditing");
textField.backgroundColor = [UIColor whiteColor];
return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
NSLog(@"textFieldDidEndEditing");
[tableView reloadData];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"touchesBegan:withEvent:");
[self.view endEditing:YES];
[super touchesBegan:touches withEvent:event];
}
#pragma mark -
#pragma mark - UITableView Delegates 
- (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


     UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:@"FirstTableViewCell"];

     if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"FirstTableViewCell"];
        //        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
if (![firstTxt.text  isEqual: @""] && ![secondTxt.text  isEqual: @""])
{
    NSString *fir = firstTxt.text;
    NSString * sec = secondTxt.text;
    cell.textLabel.text= [NSString stringWithFormat:@"%d",[fir intValue]+[sec intValue]];
}
else
{
       cell.textLabel.text=@"";
}

    //etc.

return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

return 4;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

//   NSLog(@"testing1");



}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.layer.backgroundColor = [UIColor clearColor].CGColor;
cell.backgroundColor = [UIColor clearColor];
}
@end






.h 


 //
 //  ViewController.h
 //  TestingText


 #import <UIKit/UIKit.h>

 @interface ViewController :        UIViewController<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
 {

IBOutlet UITableView *tableView;
IBOutlet UITextField *secondTxt;
IBOutlet UITextField *firstTxt;
}


@end