TableView mit PullDown Funktion (SlimeRefresh)

W

WEBixx

Registriert
Thread Starter
Dabei seit
29.08.2012
Beiträge
3
Reaktionspunkte
0
Hallo,

ich habe eine TableView (inkl. Sections) die wunderbar funktioniert.
Jetzt würde ich gerne die ganze Tabelle neu laden (oder auch den View), sobald man einen PullDown macht.
Die Daten kommen mittels JSon, was aber eig. egal ist.

folgender Code von SlimeRefresh funktioniert, nur ich weis nicht wie ich das zusammenführen kann:
(Source: https://github.com/dbsGen/SlimeRefresh)
Code:
    // 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 Tabellendaten und das SlimeRefresh zusammen führen kann ohne das etwas überschrieben wird.

Code:
//  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
 
Glaub ich habe es hinbekommen:

Code:
.....
@synthesize sectionData,locationManager, locationData, tabler;

- (void)viewDidLoad
{
    CGRect bounds = self.view.bounds;
    bounds.size.height += 1;
    [tabler setDataSource:self];
    [tabler setDelegate:self];
    
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    [self setView:contentView];
    [[self view] addSubview:tabler];
    
    _slimeView = [[SRRefreshView alloc] init];
    _slimeView.delegate = self;
    _slimeView.upInset = 0;
    _slimeView.slimeMissWhenGoingBack = YES;
    _slimeView.slime.skinColor = [UIColor whiteColor];
    _slimeView.slime.bodyColor = [UIColor lightGrayColor];
    [tabler addSubview:_slimeView];
    
    [super viewDidLoad];
}

jetzt muss ich nur noch die aktualisierten Daten laden und anzeigen!
 
Zuletzt bearbeitet:
das sollte ja per tableView ReloadData kein problem darstellen
 
stimmt!
Bei den ersten Versuchen hatte ich das zwar mit dem [self.tabler reloadData]; versucht, jedoch an der falschen Stelle ^^
schon langsam versteh ich das ganze! gg

Danke
 
Zurück
Oben Unten