I'm relatively new to iOS development and I have a question to which I believe the answer is easy, but I can't seem to find a way to achieve it.
I have a UITableViewController
which is populated by the user tapping on a button on the NavigationBar
where the user fills in the Name, Event, Sub-Event, Amount, Date, Status and Optionally Notes. The data is saved to CoreData
and the UITableView
is populated with NSFetchedResultsController
.
The notes are completely optional and it takes the form of a UITextView
, where the other text based entries are UITextFields
.
The notes attribute is part of a Transaction Entity and is a NSString
.
Because there's no way (that I can see) to have a placeholder for the UITextView
, I've set up the default text to say "Additional Notes: " with the space at the end.
In my UITableViewController
, I want the UIImageView
(that represents the note) to only appear if:
1) The user types something completely different to "Additional Notes: " &
2) If the length of the notes textView is bigger than 0
So in my UITableViewController cellForRow, I have:
if (![transaction.notes isEqualToString:@"Additional Notes: "] && [transaction.notes length] > 0)
{
UIImageView *pin = [[UIImageView alloc] initWithFrame:CGRectMake(13, 30, 24, 25)];
pin.image = [UIImage imageNamed:@"pin"];
[customCell addSubview:pin];
}
That's working to some extent. If I add text to "Additional Notes: ", it adds the PIN to the cell.
Problems
If I remove a few letters in the notes, so "Additional Not ", it treats the if statement as true and therefore attaches a pin to the statement.
If I have a note called "Additional Notes: This is a test note", it shows the PIN in the cell. However, if I go to edit that entry and remove "This is a test note", so it's back to the default, it doesn't remove the PIN from the cell of this UITableViewController.
So my questions are:
1) Can I have a placeholder for the notes? That would solve all of my issues
2) If not, how can I achieve this process efficiently, so it's not misleading for the users thinking they have a note if they just removed one or two letters
3) Have updated notes reflect appropriately in the UITableViewController
Any guidance would be really appreciated