开发者

Pull To Refresh on iphone not working as expected

I have been using this: http://blog.leahculver.com/2010/12/iphone-pull-to-refresh.html to make the pull to refresh function in my app. But I cant see the text "Pull down to refresh...", "Release to refresh..." and "Loading...".

All I've done is copy the files into my project, link against QuartzCore 开发者_如何转开发framework, and changed the .h file of my view controller so it is a subclass of PullRefreshTableViewController. Then I added the refresh method.

Is seems that the initWithStyle method in PullRefreshTableViewController never is executed. But i should be, in my tableViewcellForRowAtIndexPath.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

cell.textLabel.text = @"Text";

return cell; }

The initWithStyle method from the PullRefreshTableViewController.m:

- (id)initWithStyle:(UITableViewStyle)style {
self = [super initWithStyle:style];
if (self != nil) {
    textPull = [[NSString alloc] initWithString:@"Pull down to refresh..."];
    textRelease = [[NSString alloc] initWithString:@"Release to refresh..."];
    textLoading = [[NSString alloc] initWithString:@"Loading..."];
    NSLog(@"in");
}
NSLog(@"out");
return self; }

The logs are never printed in the console

I really cant see where the problem is ?


Had the same problem. figured out that not initWithStyle is called instead initWithCoder is called....

so to solve your problem insert following code in your PullRefreshTableViewController.m and it works like a charm

-(id)initWithCoder:(NSCoder *)aDecoder{
NSLog(@"initWithCoder");
self = [super initWithCoder:aDecoder];
if (self != nil) {
    textPull = [[NSString alloc] initWithString:@"Pull down to refresh..."];
    textRelease = [[NSString alloc] initWithString:@"Release to refresh..."];
    textLoading = [[NSString alloc] initWithString:@"Loading..."];
}
return self;
}

best regards


If you're looking for where the text is defined, it is on Line 43 of the PullRefreshTableViewController.m

Hope this helps (if it does don't forget to vote my answer up)

M.


Try instantiating the PullRefreshTableViewController with:

PullRefreshTableViewController *tableViewController = [[PullRefreshTableViewController alloc] initWithStyle:UITableViewStylePlain];

Instantiating the UITableViewCell using initWithSyle won't have any affect on your UITableViewController subclass.

The alternative is to edit the PullRefreshTableViewController class to override - (id)init method in a similar manner as done with initWithStyle:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜