Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Haroon Akhtar
3,129 Pointsadd alert if no recipients are selected
Hi,
In ribbit for ios i want to add an UIAlertView if no recipients are selected.
I have been trying in the send button:
if (!self.recipients) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"Select some friends" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
it does not seem to work. any ideas why?
2 Answers
Stepan Ulyanin
11,318 PointsHi, if self.recipients is an array you might want to check if the number of elements is 0, something like
if ([self.recipients count] == 0) {
//show alert
}
Because if somewhere before your alert you already allocated and initialized the self.recipients BUT it doesn't have any elements, it will not be nil anymore and that will cause the logic mistake.
Haroon Akhtar
3,129 Pointsthanks stephan