gpt4 book ai didi

ios - 如果没有选择收件人则显示警报 iOS

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:00:15 25 4
gpt4 key购买 nike

我有一个页面,我们可以在其中选择要将图像发送到的收件人( friend )。但如果没有选择收件人,我们仍然可以发送消息。我想要它,以便如果没有选择收件人,我们可以显示一个 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
}
}

由于某种原因它似乎没有显示,因此我们无法向任何人发送消息。如何显示警报 View ?

最佳答案

试试这个。检查收件人对象是否为0。

- (IBAction)send:(id)sender {

if ([self.recipients count]==0) {
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
[self.tabBarController setSelectedIndex:1];
}
}

关于ios - 如果没有选择收件人则显示警报 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31877110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com