我很难在UITableViewController的viewDidLoad方法中添加子视图(UIView)
这有效:
[self.view addSubview:self.progView];
Run Code Online (Sandbox Code Playgroud)
但是你可以通过UIView progView看到表格单元格出血.
我尝试过这种方法:
[self.view.superview insertSubview:self.progView aboveSubview:self.view];
Run Code Online (Sandbox Code Playgroud)
这是尝试将progView,UIView添加到当前视图上方的superview.当我尝试这个时,UIView永远不会出现.
- 更新 -
以下是最新的尝试:
UIView *myProgView = (UIView *)self.progView; //progView is a method that returns a UIView
[self.tableView insertSubview:myProgView aboveSubview:self.tableView];
[self.tableView bringSubviewToFront:myProgView];
Run Code Online (Sandbox Code Playgroud)
结果与[self.view addSubview:self.progView]相同; UIView出现但似乎在桌子后面.
我正在尝试将代码从UITableViewController类移动到"helper"类.
该代码利用NSURLConnection来获取和解析JSON,然后填充NSMutableArray.
我想要做的是在我的助手类中调用一个返回NSMutableArray的方法.我不明白的是如何从NSURLConnection的connectionDidFinishLoading委托类(实际构建数组)返回数组,就像它来自最初调用的启动连接的方法一样.换句话说,调用NSURLConnection的方法如何获得控制权,以便它可以从整个操作中返回一个值?
以下是帮助程序类的相关方法.如何让getMovies方法返回在connectionDidFinishLoading委托类中构建的listOfMovies?
-(NSMutableArray)getMovies:(NSURL*)url {
responseData = [[NSMutableData data] retain];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
//NSURLRequest* request = [NSURLRequest requestWithURL: url cachePolicy: NSURLRequestUseProtocolCachePolicy timeoutInterval: 30.0];
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
//TODO error handling for connection
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
//---initialize the array---
listOfMovies = [[NSMutableArray alloc] init];
tmdbMovies = [[NSArray alloc] init]; …Run Code Online (Sandbox Code Playgroud) 我一直在努力在我的UITableViewController上面添加一个UIView.通过搜索,阅读和试验,我已经确定我应该只使用UIViewController而不是UITableViewController.由于各种原因,我很难完成这项工作,我想从更好的架构开始.
基本上我正在寻找可以帮助我完全以编程方式创建以下内容的示例代码/教程(没有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]; …Run Code Online (Sandbox Code Playgroud)