Reputation: 184
if i click the button NSLog shows NULL value, it’s not getting the data from textfield why?.......
Delegate methods working properly.................
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellID"];
if (indexPath.row == 0) {
self.nameTextField = [[UITextField alloc]init];
self.nameTextField.frame =CGRectMake(25, 0, 300, 50);
self.nameTextField.placeholder = @"Name";
self.nameTextField.keyboardType = UIKeyboardTypeAlphabet;
[cell addSubview:self.nameTextField];
self.nameTextField.delegate = self;
return cell;
}
if (indexPath.row == 1) {
self.button = [UIButton buttonWithType:UIButtonTypeSystem];
self.button.frame = CGRectMake(100, 10, 135, 50);
[self.button setTitle:@"StoreData" forState:UIControlStateNormal];
[self.button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:self.button];
return cell;
}
return nil;
}
-(void)buttonClicked:(id) sender {
if (sender == self.phoneTextField) {
self.nameString = self.nameTextField.text;
}
NSLog(@"Name : %@", self.nameString);
}
Upvotes: 0
Views: 61
Reputation: 2438
the parameter
in the action function
is the button not the textField
-(void)buttonClicked:(id) sender {
if (sender == self.button) {
self.nameString = self.nameTextField.text;
}
NSLog(@"Name : %@", self.nameString);
}
Upvotes: 1