खोज…


परिचय

एक UIRefreshControl ऑब्जेक्ट एक मानक नियंत्रण प्रदान करता है जिसका उपयोग तालिका दृश्य की सामग्री को ताज़ा करने के लिए किया जा सकता है। आप संबंधित टेबल व्यू कंट्रोलर ऑब्जेक्ट के माध्यम से एक टेबल पर रिफ्रेश कंट्रोल लिंक करते हैं। तालिका दृश्य नियंत्रक नियंत्रण को तालिका की दृश्य उपस्थिति में जोड़ने और उपयुक्त उपयोगकर्ता के इशारों के जवाब में उस नियंत्रण के प्रदर्शन को प्रबंधित करने का काम संभालता है।

उद्देश्य-सी उदाहरण

पहले ViewController में इस तरह से एक संपत्ति की घोषणा करें

@property (nonatomic) UIRefreshControl *refreshControl;

बाद में viewDidLoad() में दिए गए रिफ्रेशकंट्रोल को नीचे दिए अनुसार सेट करें:

self.refreshControl = [[UIRefreshControl alloc]init];
[self.tableView addSubview:self.refreshControl];
[self.refreshControl addTarget:self action:@selector(refreshTable) forControlEvents:UIControlEventValueChanged];
//Setting the tint Color of the Activity Animation
self.refreshControl.tintColor = [UIColor redColor];
//Setting the attributed String to the text
NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:@"firstsecondthird"];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,5)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(5,6)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(11,5)];
self.refreshControl.attributedTitle = string;

अब फ़ंक्शन refreshTable को इस प्रकार परिभाषित किया गया है:

- (void)refreshTable {
    //TODO: refresh your data
    [self.refreshControl endRefreshing];
    [self.refreshControl beginRefreshing];
    [self.tableView reloadData];
    [self.refreshControl endRefreshing];
}

परिणामी ताज़ा दृश्य है:

TableView पर रिफ्रेशकंट्रोल सेट करें:

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(pullToRefresh:) forControlEvents:UIControlEventValueChanged];
self.scrollView.alwaysBounceVertical = YES;
[self.scrollView addSubview:refreshControl];

- (void)pullToRefresh:(UIRefreshControl*) sender{
//Do work off the main thread
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    // Simulate network traffic (sleep for 2 seconds)
    [NSThread sleepForTimeInterval:2];
    //Update data
    //Call complete on the main thread
    dispatch_sync(dispatch_get_main_queue(), ^{
        //Update network activity UI
        NSLog(@"COMPLETE");
        [sender endRefreshing];
    });
});

}



Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow