Ios refreshControl附加到UIButton-刷新UILabels

Ios refreshControl附加到UIButton-刷新UILabels,ios,objective-c,uibutton,uilabel,uirefreshcontrol,Ios,Objective C,Uibutton,Uilabel,Uirefreshcontrol,我希望我的UILabel在用户发送到新内存时自动刷新。我知道我可以拉刷新,但我很好奇是否可以将刷新操作与sendMemories的iAction或此代码中最后一个UIAlertController绑定 我已经在这个网站上搜索了所有的苹果文档,但我想这是非常具体的,我对refreshControl了解不够 谢谢你的建议 这是ViewController.h #import <UIKit/UIKit.h> #import <Parse/Parse.h> #import "Ap

我希望我的UILabel在用户发送到新内存时自动刷新。我知道我可以拉刷新,但我很好奇是否可以将刷新操作与sendMemories的iAction或此代码中最后一个UIAlertController绑定

我已经在这个网站上搜索了所有的苹果文档,但我想这是非常具体的,我对refreshControl了解不够

谢谢你的建议

这是ViewController.h

#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import "AppDelegate.h"



@interface MemoriesViewController : UIViewController <UITableViewDelegate, UITextViewDelegate>


@property (nonatomic, strong) PFQuery *query;
@property (nonatomic, strong) NSArray *mainArray;
@property (strong, nonatomic) IBOutlet UITextView *memoriesField;

@property (strong, nonatomic) IBOutlet UILabel *cellCountLabel;
@property (strong, nonatomic) IBOutlet UILabel *cellPhotoCountLabel;


- (IBAction)sendMemories:(UIButton *)sender;
- (IBAction)logOut:(id)sender;



@end

有点不清楚你在问什么。更改数据时是否要更改标签的文本?标签是在tableView中还是独立标签?为什么label.text=不足?对不起。标签由Parse.com的查询填充。它们统计用户发送的消息数。当他们发送新消息(在同一屏幕上)时,标签中的数据需要刷新。您正在主线程上进行标签更新吗?所有的UI更新都需要在主线程上,现在我没有在任何地方进行更新。我尝试了几个不同的刷新控件,阅读了所有苹果文档并在这里搜索,但我找不到任何关于在按下UIButton后刷新UILabel的信息。你只需添加一个在按下按钮时触发的方法,然后在该方法中,获取你的textField,然后转到textField.text=@“所需值”;就这样
#import "MemoriesViewController.h"
#import "MSCellAccessory.h"

@interface MemoriesViewController ()

@end

@implementation MemoriesViewController

@synthesize memoriesField = _memoriesField;
@synthesize cellCountLabel = _cellCountLabel;
@synthesize cellPhotoCountLabel = _cellPhotoCountLabel;


- (void)viewDidLoad {
    [super viewDidLoad];

    [self.navigationController.navigationBar setHidden:NO];

    _mainArray = [[NSArray alloc] initWithObjects:@"senderName", nil];

    self.memoriesField.delegate = self;

    PFUser *currentUser = [PFUser currentUser];
    if (currentUser) {
        NSLog(@"Current user: %@", currentUser.username);
    }
    else {
        [self performSegueWithIdentifier:@"showLogin" sender:self];
    }

    PFQuery *query = [PFQuery queryWithClassName:@"Memories"];
    [query whereKey:@"senderName" equalTo:[[PFUser currentUser] username]];
    [query countObjectsInBackgroundWithBlock:^(int count, NSError *error) {
        if (!error)
            NSLog (@"You have %d Memories Saved", count);
        self.cellCountLabel.text = [NSString stringWithFormat:@"You have %d Memories Saved", count];
    }];

    PFQuery *query2 = [PFQuery queryWithClassName:@"Photos"];
    [query2 whereKey:@"senderName" equalTo:[[PFUser currentUser] username]];
    [query2 countObjectsInBackgroundWithBlock:^(int count, NSError *error) {
        if (!error)
                NSLog (@"You have %d Photos Saved", count);
        self.cellPhotoCountLabel.text = [NSString stringWithFormat:@"You have %d Photos Saved", count];
    }];
}




- (IBAction)sendMemories:(UIButton *)sender {

    //Place the loading spinner
    UIActivityIndicatorView *loadingSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

    [loadingSpinner setCenter:CGPointMake(self.view.frame.size.width/2.0, self.view.frame.size.height/2.0)];
    [loadingSpinner startAnimating];

    [self.view addSubview:loadingSpinner];

    PFObject *memories = [PFObject objectWithClassName:@"Memories"];
    memories[@"Memories"] = self.memoriesField.text;
    [memories setObject:[[PFUser currentUser] username] forKey:@"senderName"];
    [memories saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (succeeded){
            NSLog(@"succeeded");
            self.memoriesField.text = nil;
        }
        else{
            NSLog(@"problem");
            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Our Apologies" message:@"Your Memory was not Recieved" preferredStyle:UIAlertControllerStyleAlert];

            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"Ok"
                                                                    style:UIAlertActionStyleDefault
                                                                  handler:^(UIAlertAction * action) {}];

            [alert addAction: defaultAction];
        }
            NSString *memories = [self.memoriesField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        [self.view endEditing:YES];

    if ([memories length] == 0)
    {
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Memory Recieved!" message:@"" preferredStyle:UIAlertControllerStyleAlert];

        UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"Ok"
                                                                style:UIAlertActionStyleDefault
                                                              handler:^(UIAlertAction * action) {}];

        [alert addAction: defaultAction];
        [self presentViewController:alert animated:YES completion:nil];
    }
    else {
        [self.navigationController popToRootViewControllerAnimated:YES];
            }
        }];
    }

#pragma mark - log out method

- (IBAction)logOut:(id)sender {
    [PFUser logOut];
    [self performSegueWithIdentifier:@"showLogin" sender:self];
}


#pragma mark - UITextField Delegate Methods

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {

    if([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }

    return YES;

}
@end