[C] iOS - TableView mit PullDown Funktion (SlimeRefresh)

WEBi

Mitglied
[objective-c] iOS - TableView mit PullDown Funktion (SlimeRefresh)

Hallo,

ich habe eine TableView die wunderbar funktioniert.
Jetzt würde ich gerne die ganze Tabelle neu laden, sobald man einen PullDown macht.

folgender Code von SlimeRefresh funktioniert, nur ich weis nicht wie ich das zusammenführen kann:
(Source: https://github.com/dbsGen/SlimeRefresh)
C++:
    // Custom initialization
    CGRect bounds = self.view.bounds;
    _tableView = [[UITableView alloc] initWithFrame:bounds];
    bounds.size.height += 1;
    _tableView.contentSize = bounds.size;
    _tableView.delegate = self;
    [self.view addSubview:_tableView];
    
    _slimeView = [[SRRefreshView alloc] init];
    _slimeView.delegate = self;
    _slimeView.upInset = 0;
    _slimeView.slimeMissWhenGoingBack = YES;
    
    [_tableView addSubview:_slimeView];

Wenn ich diesen Code einfüge, wird meine Tabelle natürlich überschrieben und somit nur leere Zeilen angezeigt :-/
Aber der PullDown "Effekt" wird angezeigt ;)

Mir fehlt der Zusammenhang wo ich die Daten und das SlimeRefresh zusammen führen kann.
Mach das ganze erst seit ein paar Tagen...

C++:
//  pvViewController.m

#import "pvViewController.h"
#import "pvCellViewController.h"

@interface pvViewController () <CLLocationManagerDelegate, UITableViewDelegate, SRRefreshDelegate>
@end

@implementation pvViewController {
    SRRefreshView   *_slimeView;
    UITableView     *_tableView;
}

@synthesize sectionData,locationManager, locationData;

- (void)viewDidLoad
{
    // Custom initialization
    CGRect bounds = self.view.bounds;
    _tableView = [[UITableView alloc] initWithFrame:bounds];
    bounds.size.height += 1;
    _tableView.contentSize = bounds.size;
    _tableView.delegate = self;
    [self.view addSubview:_tableView];
    
    _slimeView = [[SRRefreshView alloc] init];
    _slimeView.delegate = self;
    _slimeView.upInset = 0;
    _slimeView.slimeMissWhenGoingBack = YES;
   
    [_tableView addSubview:_slimeView];
 
    [super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated
{
    [self loadEvents];
}

- (void)loadEvents
{
    NSString *requestUrl= [NSString stringWithFormat:@"http://www.url.com",...];
    
    NSString *jsonString = [NSString
                            stringWithContentsOfURL:[NSURL URLWithString:requestUrl]
                            encoding:NSStringEncodingConversionAllowLossy
                            error:nil];
    
    SBJsonParser *parser = [[SBJsonParser alloc] init];
    NSDictionary *results = [parser objectWithString:jsonString error:nil];
    [self setSectionData:[results objectForKey:@"sections"]];
    
    parser = nil;
    jsonString = nil;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [sectionData count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSDictionary* sectionDictionary = [sectionData objectAtIndex:section];
    return [sectionDictionary objectForKey:@"items"];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSDictionary *sectionDictionary = [sectionData objectAtIndex:section];
	NSArray* sectionEntries = [sectionDictionary objectForKey:@"event"];
	return [sectionEntries count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"eventCell";
    pvCellViewController *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil) {
        cell = [[pvCellViewController alloc]
                 initWithStyle:UITableViewCellStyleSubtitle
                 reuseIdentifier:CellIdentifier];
    }
     
    // Get item from sectionData
    NSDictionary *item = [sectionData objectAtIndex:[indexPath section]];

    NSArray* sectionEntries = [item objectForKey:@"event"];
    NSDictionary *row = [sectionEntries objectAtIndex:[indexPath row]];
    
    // Set text on textLabel
    [[cell nameLabel] setText:[row objectForKey:@"name"]];
    [[cell descLabel] setText:[row objectForKey:@"beschreibung"]];

    return cell;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

#pragma mark - scrollView delegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    [_slimeView scrollViewDidScroll];
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    [_slimeView scrollViewDidEndDraging];
}

#pragma mark - slimeRefresh delegate

- (void)slimeRefreshStartRefresh:(SRRefreshView *)refreshView
{
    [_slimeView performSelector:@selector(endRefresh)
                     withObject:nil afterDelay:3
                        inModes:[NSArray arrayWithObject:NSRunLoopCommonModes]];
}
@end
 
Zuletzt bearbeitet:

Neue Beiträge

Zurück