獲取UITableViewCell中UITextField的值方法總結
UITableViewCell的contentView中的UITextField的值獲取有幾種方法,本人簡單總結一下。
1. 獲取UITextField所以Cell的NSIndexPath,知道了NSIndexPath就知道了這個UITextField是幹什麼的了。
可以在
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
//get cell
UITableViewCell *cell = [UITableViewCell ][[textField superview] superview];
NSIndexPath *indexPath = [tableView indexPathForCell:cell];
}
或
- (void)textFieldDidEndEditing:(UITextField *)textField
{
//get cell
UITableViewCell *cell = (UITableViewCell *)[[textField superview] superview];
NSIndexPath *indexPath = [tableView indexPathForCell:cell];
}
中得知道UITextField中text是哪一個資料結構的值,前一個是實時的,後一個是失去焦點時一次性的。
2。第二種方法與上面第一個有點類似也是實時的,來自:http://blog.sina.com.cn/s/blog_9ca91e4a0100xlvu.html
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger row = [indexPath row];
static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text = [_passwordArray objectAtIndex:row];
CGRect textFieldRect = CGRectMake(0.0, 0.0f, 215.0f, 31.0f);
UITextField *theTextField = [[UITextField alloc] initWithFrame:textFieldRect];
theTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
theTextField.returnKeyType = UIReturnKeyDone;
theTextField.secureTextEntry = YES;
theTextField.clearButtonMode = YES;
theTextField.tag = row;
theTextField.delegate = self;
//此方法為關鍵方法
[theTextField addTarget:self action:@selector(textFieldWithText:) forControlEvents:UIControlEventEditingChanged];
switch (row) {
case 0:
theTextField.placeholder = @"請輸入舊密碼";
break;
case 1:
theTextField.placeholder = @"請輸入新密碼";
break;
case 2:
theTextField.placeholder = @"請再次輸入新密碼";
break;
default:
break;
}
cell.accessoryView = theTextField;
[theTextField release];
return cell;
}
- (void)textFieldWithText:(UITextField *)textField
{
switch (textField.tag) {
case 0:
self.theOldPassword = textField.text;
break;
case 1:
self.theNewPassword = textField.text;
break;
case 2:
self.theTwiceNewPassword = textField.text;
break;
default:
break;
}
}
相關文章
- Shell指令碼中獲取SELECT結果值的方法指令碼
- python中取絕對值簡單方法總結Python
- C#獲取根目錄的方法總結C#
- layer父介面呼叫子彈窗的方法和獲取子彈窗的元素值總結
- 獲取sql繫結變數的值SQL變數
- 總結C#獲取當前路徑的7種方法C#
- Python中獲取執行緒返回值的常用方法!Python執行緒
- UITableViewCell的高度快取UIView快取
- Laravel 中 $request 獲取請求資訊 用法 總結Laravel
- 微信小程式獲取index索引值的方法微信小程式Index索引
- python request 獲取cookies value值的方法PythonCookie
- 在cs頁面獲取input的值方法
- ORACLE 獲取繫結變數值Oracle變數
- 如何獲取繫結變數值變數
- JS獲取URL中引數值(QueryString)的4種方法分享JS
- 【百度知道總結】獲取一個圖片地址中圖片名稱的方法
- js 獲取被選中核取方塊的值JS
- python中獲取如何Series值Python
- listview 後天獲取選中項的值View
- gitlab cicd中獲取tag值的方式Gitlab
- 使用awk和sed獲取檔案奇偶數行的方法總結
- Java獲取Object中Value的方法JavaObject
- 陣列呼叫c#讀取陣列中獲取最大最小值方法陣列C#
- JavaScript 獲取選中checkbox核取方塊的值JavaScript
- jquery獲取選中checkbox核取方塊的值jQuery
- js獲取選中checkbox核取方塊的值JS
- javascript獲取選中checkbox核取方塊的值JavaScript
- iOS 點選UITableViewCell上的控制元件獲取對應的celliOSUIView控制元件
- jQuery獲取選中的checkbox核取方塊的值jQuery
- js獲取裝置資訊的方法彙總JS
- 對getElementsByTagName("*")獲取全部元素的總結
- 通過url動態獲取圖片大小方法總結
- JavaScript獲取css的值JavaScriptCSS
- js如何獲取陣列中的最大值JS陣列
- 求救!Javabean中能否獲取某個session的值??JavaBeanSession
- JAVA獲取json中的全部鍵值對JavaJSON
- ListView新增事件並獲取選中項的值View事件
- js獲取元素的方法(獲取html元素的方法)JSHTML