I have a custom editable UITableview
, and my question is how to store it's value in NSDictionary
when I tapped on submit button. My table is like a simple registration form.
Expanding on my comment:
If I understand you, you want to get data from a UItableViewCell back into the viewController with the tableView and dictionary.
There are two main ways of doing this, you can create a delegate for the cell or create a block on the cell. So once the textfilds are finished being edited call the delegate/block with the new data. Then have the vc save it
Using a block:
MyTableViewCell.h
@interface MyTableViewCell : UITableViewCell
@property (nonatomic, copy) void (^nameChangedBlock)(NSString *name);
@end
MyTableViewCell.m
In something like textfield didFinishEditing:
- (void)textFieldDidFinishEditing:(UITextField *)textField {
if (textField == self.nameTextfield) {
self.nameChangedBlock(textField.text)
}
}
In the ViewController with the TableView, in the datasource method cellforRow
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Do your standard stuff create the cell and set data;
// dequeueReusableCellWithIdentifier: blah blah
cell.nameChangedBlock = ^{
// Alex j thank you
[yourNSMutableDictionary setObject:yourobject forKey:yourkey];
};
return cell
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다