开发者

why does TTTableViewDragRefreshDelegate not work

My class is like:

- (id)init
{
NSLog(@"lalallalalala");
if (self = [super init]) {
    self.title = @"lalal";

    UIImage* image = [UIImage imageNamed:@"tab.png"];
    self.tabBarItem = [[[UITabBarItem alloc] initWithTitle:self.title image:image tag:0] autorelease];
    self.variableHeightRows = YES;
    id<TTTableViewDataSource> ds = [MainPageDataSource dataSourceWithItems:nil];
    ds.model = CreateTabModelWithCurrentSettings();
    self.dataSource = ds;

}
return self;
}




- (void)loadView
{
// Create the tableview.

NSLog(@"in MainPageController");

//self.view = [[[UIView alloc] initWithFrame:TTApplicationFrame()] autorelease];
self.view  =[[UIView alloc] init];
self.tableView = [[[UITableView alloc] initWithFrame:TTApplicationFrame() style:UITableViewStylePlain] autorelease];

self.tableView.rowHeight = 80.f;
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.tableView];


}



- (id<UITableViewDelegate>)createDelegate {
   return [[[TTTableViewDragRefreshDelegate alloc] initWithController:self] autorelease];
}

CreateDelegate seems not work, no drag & refresh appears. I don't know what's wrong with my code.

@aporat the view controller does extend TTTableViewController and my code changed to:

- (id)init
{
NSLog(@"lalallalalala");
if (self = [super init]) {
    self.title = @"app";

    UIImage* image = [UIImage imageNamed:@"t开发者_如何学JAVAab.png"];
    self.tabBarItem = [[[UITabBarItem alloc] initWithTitle:self.title image:image tag:0] autorelease];
    self.variableHeightRows = YES;
    //id<TTTableViewDataSource> ds = [MainPageDataSource dataSourceWithItems:nil];
    //        ds.model = CreateTabModelWithCurrentSettings();
    //      self.dataSource = ds;
    //self.dataSource = [[[MainPageDataSource alloc] init] autorelease];

}
return self;
}


- (void)createModel {
NSLog(@"in createModel");
self.dataSource = [[[MainPageDataSource alloc] init] autorelease];
}

//- (void)loadView
//{
//    // Create the tableview.
//  
//  NSLog(@"in MainPageController");
//  
//    self.view = [[[UIView alloc] initWithFrame:TTApplicationFrame()] autorelease];
//  //self.view  =[[UIView alloc] init];
//    self.tableView = [[[UITableView alloc] initWithFrame:TTApplicationFrame()  style:UITableViewStylePlain] autorelease];
//  self.toolbarItems = [NSArray arrayWithObjects:
//                       [TTButton buttonWithStyle:@"toolbarButton:" title:@"Toolbar Button"],
//                       [TTButton    buttonWithStyle:@"toolbarRoundButton:" title:@"Round Button"],
//                       nil]; 
//  
//    self.tableView.rowHeight = 80.f;
//    self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
//    [self.view addSubview:self.tableView];
//  
//
//}
//- (void)viewDidLoad {
//  [super viewDidLoad];
//  
//  self.navigationController.navigationBar.alpha = 0;
//}


- (id<UITableViewDelegate>)createDelegate {
return [[[TTTableViewDragRefreshDelegate alloc] initWithController:self] autorelease];
}

Still not appears drag & fresh


There are a few issues with your code:

  • Your view controller has to extend TTTableViewController
  • Don't override self.view & self.tableView in loadView. The TTTableViewController load these views for you.
  • Create your datasource using the standard method. This function is called automatically if you're using TTTableViewController:

    ///////////////////////////////////////////////////////////////////////////////////////////////////
    - (void)createModel {
        self.dataSource = [[[CurrencyDataSource alloc] init] autorelease];
     }
    

What happens if you call this function directly? (This should manually display the drag to refresh header)

///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)reload {

  if ([self.tableView.delegate isKindOfClass:[TTTableViewDragRefreshDelegate class]]) {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:ttkDefaultFastTransitionDuration];
    self.tableView.contentOffset = CGPointMake(0, -60.0f);
    [UIView commitAnimations];
  }

  [super reload];
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜