我一直在努力在UITableViewController上添加一個UIView。通過搜索,閱讀和試驗我已經確定,而不是一個UITableViewController,我應該只是使用UIViewController。由於各種各樣的原因,我很難做這項工作,我想用更好的體系結構重新開始。如何以編程方式創建UIView - > UIViewController - > UITableView
基本上我正在尋找的代碼示例/教程,可以幫助我創建完全編程以下(無NIBS):
- Navigation-based Layout - UIViewController -- UIView --- UITableView --- Etc.
爲什麼我想我上面的UITableView一個UIView是我想成爲的原因能夠在我的桌子上面添加UIViews。
-UPDATE-
添加代碼,以使這更清楚:
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
。
爲什麼你想避免筆尖? – kubi 2011-01-13 18:22:34