0

有没有办法在网络连接期间设置查看页面模式?我的意思是如果网络正在连接,页面中的所有控制器都不会响应用户操作?


我更新了如下代码:

- (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 的按钮,用户仍然可以单击这些按钮......

4

1 回答 1

0

不要使用 modalViewController,而是创建一个 HUD(您将在 TTCatalogue 应用程序中看到的带有 UIActivityIndi​​cators 的漂亮视图之一),它将阻止视图并在您发出请求时通知用户正在发生的事情。只需将它们插入[self.view addSubview:theHUDview];.

不过,这不一定是好的设计,相反,在后台异步调用您的网络。

于 2011-08-16T14:22:22.507 回答