0

嗨,我创建了一个自定义选项卡栏,它隐藏和显示某些 Web 视图,具体取决于您当前在操作队列上加载所有三个 Web 视图的选项卡,然后根据所选选项卡使它们可见和不可见。问题是加载和滚动速度太慢了,我收到了内存警告

这是我到目前为止所做的

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    NSArray *subviews = [cell subviews];
        for(UIView *subview in subviews) if([subview tag] == 4) [subview removeFromSuperview];

        UIView *loadingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 800)];
        UIView *sendingMessage = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
        UIActivityIndicatorView *sendingSpinner = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(25, 15, 50, 50)];
        UILabel *sendingLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 65, 100, 20)];

        int sendingViewLeft = (loadingView.frame.size.width/2) - (sendingMessage.frame.size.width/2);
        int sendingViewTop = 160 - (sendingMessage.frame.size.height/2);

        loadingView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];

        sendingMessage.frame = CGRectMake(sendingViewLeft, sendingViewTop, sendingMessage.frame.size.width, sendingMessage.frame.size.height);
        sendingMessage.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
        sendingMessage.layer.cornerRadius = 10;

        sendingSpinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;

        sendingLabel.textColor = [UIColor whiteColor];
        sendingLabel.backgroundColor = [UIColor clearColor];
        sendingLabel.text = @"Loading...";
        sendingLabel.textAlignment = UITextAlignmentCenter;
        sendingLabel.font = [UIFont boldSystemFontOfSize:12];
        sendingLabel.shadowColor = [UIColor blackColor];
        sendingLabel.shadowOffset = CGSizeMake(0, -1);

        [sendingSpinner startAnimating];
        [sendingMessage addSubview:sendingLabel];
        [sendingMessage addSubview:sendingSpinner];
        [loadingView addSubview:sendingMessage];

        [loadingView setTag:4];

       cell.textLabel.text = @"";


    if([self.webViewStatus isEqualToString:@"FALSE"]){
        [cell addSubview:loadingView];
        self.tableView.userInteractionEnabled = NO;
    } else {
        [cell addSubview:self.fixturesWebView];
        [cell addSubview:self.resultsWebView];
        [cell addSubview:self.tablesWebView];
        self.tableView.userInteractionEnabled = YES;
    }


    if(self.selectedTabNumber == 1){
        self.fixturesWebView.alpha = 1;
        self.resultsWebView.alpha = 0;
        self.tablesWebView.alpha = 0;
    }

    if(self.selectedTabNumber == 2){
        self.fixturesWebView.alpha = 0;
        self.resultsWebView.alpha = 1;
        self.tablesWebView.alpha = 0;
    }

    if(self.selectedTabNumber == 3){
        self.fixturesWebView.alpha = 0;
        self.resultsWebView.alpha = 0;
        self.tablesWebView.alpha = 1;

    }

    return cell;
}
4

1 回答 1

0

首先,您应该考虑创建一个自定义单元格,而不是在 tableview 数据源中创建它。其次,当您获取 webview 内容时,请考虑使用异步调用来避免锁定。这也可以在一个块中完成。如果您在自定义单元格上编写委托方法,您可以让 tableview 知道什么时候加载或不加载等等。

但是当 tableview 需要绘制一个单元格时,看起来你正在让它做太多的工作。

于 2012-10-26T15:54:56.290 回答