Scenario:
I have two UITableViewCells containing a UITextField property and UITextView property respectively. Obviously both of these properties have properties in common, such as ‘text’ and ‘textColor’
Objective:
Indiscriminately assign a string to the UITextField/UITextView’s text property without raising compiler warnings. Can it be done?
Here’s an example of what I’m doing:
Currently I do this to avoid compiler warnings:
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
UITextField *textField;
UITextView *textView;
switch (indexPath.section) {
case SectionDescription:
textField = (UITextField *)[(TextFieldCell *)cell contents];
textField.text = self.plan.description;
break;
case SectionNotes:
textView = (UITextView *)[(TextViewCell *)cell contents];
textView.text = self.plan.notes;
break;
}
But I’d like to do something closer to this without the compiler warnings:
NSString *contents = [self getContents];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
UIView *textView = (?? *)[(?? *)cell contents];
textView.text = contents;
Is there a standard way to do this? I know if both objects conformed to a common protocol I could do something like “UIView *textView = [cell contents];” Is there an answer to this question?
Try using
[(id)textView setText:contents].