为什么TTTableViewDragRefreshDelegate不起作用

时间:2011-07-11 07:15:20

标签: three20

我的班级就像:

- (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似乎不起作用,没有拖累和放大刷新出现。我不知道我的代码有什么问题。

@aporat视图控制器确实扩展了TTTableViewController,我的代码改为:

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

    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;
    //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];
}

仍然没有出现阻力&amp;新鲜

1 个答案:

答案 0 :(得分:0)

您的代码存在一些问题:

  • 您的视图控制器必须扩展TTTableViewController
  • 不要覆盖self.view&amp; loadView中的self.tableView。 TTTableViewController为您加载这些视图。
  • 使用标准方法创建数据源。如果您使用的是TTTableViewController

    ,系统会自动调用此函数
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    - (void)createModel {
        self.dataSource = [[[CurrencyDataSource alloc] init] autorelease];
     }
    

如果直接调用此函数会怎样? (这应该手动显示拖动以刷新标题)

///////////////////////////////////////////////////////////////////////////////////////////////////
- (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];
}