テキストフィールドの下にビューコントローラのテキストフィールドがあります。私は、テーブルビューを使用してデータを表示しています。また、テーブルビューのデータをクリックすると、テキストフィールドに表示されます。今すぐテーブルビューの任意のセルを押すと、そのテキストフィールドにデータは表示されますが、テキストフィールドはテーブルビューからデータを取得しませんが、テキストフィールドに手動でデータが書き込まれます。それは、このコンソールで、IOSのテキストフィールドの問題
<UITableViewCell: 0x7f9dad0a1000; frame = (0 132; 342 44); text = '2014'; autoresize = W; layer = <CALayer: 0x60400022ec20>>
私のコードはこれです、
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView==_year01) {
return [year1Array count];
}else if (tableView == _carTable){
return [carArray count];
}
return YES;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (tableView == _year01){
cell.textLabel.text=[year1Array objectAtIndex:indexPath.row];
}else if (tableView == _carTable){
cell.textLabel.text=[carArray objectAtIndex:indexPath.row];
}
cell.backgroundColor=[UIColor darkGrayColor];
cell.textLabel.textColor=[UIColor whiteColor];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *selectedCell=[tableView cellForRowAtIndexPath:indexPath];
NSLog(@"Cell %@",selectedCell);
if (tableView == _year01){
self.year1.text=[year1Array objectAtIndex:indexPath.row];
self.year01.hidden=YES;
}else{
self.carName.text=[carArray objectAtIndex:indexPath.row];
_carTable.hidden=YES;
[_carName resignFirstResponder];
}
}
テキストフィールドにスペースを管理するためのコードは、これは次のビューにデータを送信し、
-(void)textFieldDidChanges :(UITextField *)theTextField{
result=self.carName.text;
result=[result stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSLog(@"RRR %@",result);
//just use this result where you want
}
、
である私を示してい- (IBAction)okay:(id)sender {
if ([_carName.text isEqualToString:@""] || [_year1.text isEqualToString:@""] || [_year2.text isEqualToString:@""]) {
NSString *message = @"Fill all the fields";
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Enter Data"
message:message
preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alert animated:YES completion:nil];
int duration = 2; // duration in seconds
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[alert dismissViewControllerAnimated:YES completion:nil];
});
_guideView.hidden=YES;
}else{
NSString *strAppend = [NSString stringWithFormat:@"%@-%@",_year1.text,_year2.text];
NSLog(@"%@",strAppend);
[[NSUserDefaults standardUserDefaults] setObject:result forKey:@"name"];
[[NSUserDefaults standardUserDefaults] setObject:strAppend forKey:@"year"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
それはUITableViewCellのインスタンスを出力しますので、あなたはselectedCellを印刷しています。あなたのテキストフィールドがどんなものなのか、実際に何を達成したいのかなど、より多くの文脈を説明してください。 –
Self.carNameは私がそれをクリックするとmuのテキストフィールドです。それは私にテーブルビューからの車の名前を選択すると、それは私がテキストのフィールドにその名前を表示するが、私はそれを送信するその価値は私が最初に書いた2〜3語になります。 @RozarioRapheal – Faheem
textField.text = ""でテキストフィールドをクリアしてから、carnameを設定することができます。 –