在网络连接期间有没有办法设置视图页模式?我的意思是,如果网络连接,页面中的所有控制器都不响应用户操作?
我更新了代码:
- (void)loadView
{
[super loadView];
_hudView = [[UIView alloc] initWithFrame:CGRectMake(75, 155, 170, 170)];
_hudView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
_hudView.clipsToBounds = YES;
_hudView.layer.cornerRadius = 10.0;
_activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
_activityIndicatorView.frame = CGRectMake(65, 40, _activityIndicatorView.bounds.size.width, _activityIndicatorView.bounds.size.height);
[_hudView addSubview:_activityIndicatorView];
[_activityIndicatorView startAnimating];
_captionLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 115, 130, 22)];
_captionLabel.backgroundColor = [UIColor clearColor];
_captionLabel.textColor = [UIColor whiteColor];
_captionLabel.adjustsFontSizeToFitWidth = YES;
_captionLabel.textAlignment = UITextAlignmentCenter;
_captionLabel.text = @"Loading...";
[_hudView addSubview:_captionLabel];
NSArray *buttonNames = [NSArray arrayWithObjects:@"hehe",@"xixi",nil];
UISegmentedControl *segmentControl = [[UISegmentedControl alloc] initWithItems:buttonNames];
segmentControl.frame = CGRectMake(0, 0, TTApplicationFrame().size.width/2, TT_ROW_HEIGHT-10);
segmentControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentControl.momentary = NO;
segmentControl.tintColor = [UIColor darkGrayColor];
segmentControl.selectedSegmentIndex = 0;
[segmentControl addTarget:self action:@selector(switchPage:) forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView = segmentControl;
TT_RELEASE_SAFELY(segmentControl);
self.view = [[[UIView alloc] initWithFrame:TTApplicationFrame()] autorelease];
self.tableView = [[[UITableView alloc] initWithFrame:TTApplicationFrame() style:UITableViewStylePlain] autorelease];
self.tableView.rowHeight = 80.f;
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:self.tableView];
[self reload];
[self updateView];
}
并显示如下:
- (void)showLoading:(BOOL)show {
if (show) {
self.loadingView = _hudView;
}
else {
self.loadingView = nil;
}
}
正如我在评论中所说,它仍然无法覆盖UISegmentedControl的按钮,用户仍然可以点击那些按钮......
答案 0 :(得分:0)
创建HUD(使用您在TTCatalogue应用程序中看到的UIActivityIndicators的优秀视图之一)而不是使用modalViewController,它将阻止视图并在您发出请求时通知用户正在发生的事情。
只需按[self.view addSubview:theHUDview];
插入即可。
但它不一定是好的设计,而是在后台异步进行网络调用。