【发布时间】:2011-06-08 16:26:36
【问题描述】:
我一直在努力在我的 UITableViewController 上方添加一个 UIView。通过搜索、阅读和试验,我确定我应该只使用 UIViewController 而不是 UITableViewController。由于各种原因,我很难完成这项工作,我想从一个更好的架构重新开始。
基本上,我正在寻找可以帮助我完全以编程方式(无 NIBS)创建以下内容的示例代码/教程:
- 基于导航的布局 - UIViewController -- 界面视图 --- UITableView - - 等等。我想要在 UITableView 上方添加 UIView 的原因是我希望能够在表格上方添加 UIView。
-更新-
添加代码以使其更清晰:
JMoviesListViewController.m - UITableViewController 子类
- (void)loadView
{
NSLog(@"loadView called");
UIView *baseView = [[[UIView alloc] init] autorelease];
TISwipeableTableView * aTableView = [[[TISwipeableTableView alloc] init] autorelease];
[aTableView setDelegate:self];
[aTableView setDataSource:self];
[aTableView setSwipeDelegate:self];
[aTableView setRowHeight:54];
[baseView addSubview:aTableView];
self.view = baseView;
[super loadView];
}
- (void)viewDidLoad {
listOfMovies = [[NSMutableArray alloc] init];
UIView *myProgView = (UIView *)self.progView; // progView is a method that returns a UIView
[self.view insertSubview:myProgView aboveSubview:self.tableView];
[self.navigationItem setTitle:@"Now Playing"];
movies = [[Movies alloc] init];
movies.delegate = self;
[movies getMovies:[NSURL URLWithString:apiQuery]];
[super viewDidLoad];
}
- (UIView *)progView {
if (progView == nil)
{
// create a progress view
//x,y,w,h
progView = [[UIView alloc] initWithFrame:CGRectMake(110, 110, 95, 30)];
progView.backgroundColor = [UIColor grayColor];
progView.tag = 1; // tag this view for later so we can remove it from recycled table cells
progView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin);
progView.layer.cornerRadius = 5;
UILabel *activityLabel = [[UILabel alloc] init];
activityLabel.text = NSLocalizedString(@"Loading...", @"string1");
activityLabel.backgroundColor = [UIColor grayColor];
activityLabel.textColor = [UIColor whiteColor];
activityLabel.font = [UIFont systemFontOfSize:14];
[progView addSubview:activityLabel];
activityLabel.frame = CGRectMake(5, 2, 70, 25);
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[activityIndicator startAnimating];
[progView addSubview:activityIndicator];
activityIndicator.frame = CGRectMake(70, 5, 20, 20);
}
return progView;
}
需要明确的是,代码工作正常,问题是表格的单元格行正在“渗入”使用此行插入的 UIView 微调器:
[self.view insertSubview:myProgView aboveSubview:self.tableView];
让我相信myProgView 不是aboveSubview:self.tableView。
【问题讨论】:
-
你为什么要避免使用笔尖?
标签: iphone objective-c ios4