我有一个页面,我们在其中选择要向其发送图像的收件人(他们是朋友)。但如果没有选择收件人,我们仍然可以发送邮件。我希望这样,如果没有选择收件人,我们可以显示UIAlertView。对我来说,当我尝试显示警报时,它不起作用,请查看下面的代码。
.h
@property (nonatomic, strong) NSArray *friends;
@property (nonatomic, strong) PFRelation *friendsRelation;
@property (nonatomic, strong) NSMutableArray *recipients;
- (IBAction)send:(id)sender;
.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.recipients = [[NSMutableArray alloc] init];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.friendsRelation = [[PFUser currentUser] objectForKey:@"friendsRelation"];
PFQuery *query = [self.friendsRelation query];
[query orderByAscending:@"username"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error) {
NSLog(@"Error %@ %@", error, [error userInfo]);
}
else {
self.friends = objects;
[self.tableView reloadData];
}
}];
//display camera modally etc......
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
PFUser *user = [self.friends objectAtIndex:indexPath.row];
cell.textLabel.text = user.username;
if ([self.recipients containsObject:user.objectId]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
PFUser *user = [self.friends objectAtIndex:indexPath.row];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[self.recipients addObject:user.objectId];
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
[self.recipients removeObject:user.objectId];
}
NSLog(@"%@", self.recipients);
}
这是我尝试显示警报的部分
- (IBAction)send:(id)sender {
if (!self.recipients) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"Select some friends" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
} else {
[self uploadMessage];
//we upload the message in method to parse.com
}
}
由于某种原因,它似乎没有显示,因此我们无法向任何人发送消息。如何显示警报视图?