只有两个UITableView中的一个正在加载

时间:2014-06-01 15:54:23

标签: ios objective-c uitableview

我有两个tableviews,只有person tableview正在加载数据。如何在一个视图控制器上处理多个uitableviews?以下是我目前使用.m文件的内容。表视图人员是我得到的唯一日志返回我还应该记录如果这是正常工作的TABLE VIEW EXPECTATIONS(当然还有数据加载到期望表视图中)

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    if(tableView == self.listPersonTableView)
        return  1;
    else if(tableView == self.listExpectationsTableView)
        return  1;
    else
        return 0;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(tableView == self.listPersonTableView)
        return  [arrayOfPersons count];
    else if(tableView == self.listExpectationsTableView)
        return  [arrayOfExpectations count];
    else
        return 0;

}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(!cell){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }

    if(tableView == self.listPersonTableView){
        Person *person = [arrayOfPersons objectAtIndex:indexPath.row];

        cell.textLabel.text = person.personName;
    NSLog(@"TABLE VIEW PERSONS");
        return cell;
}
    else if(tableView == self.listExpectationsTableView){
        Expectations *expectation = [arrayOfExpectations objectAtIndex:indexPath.row];

        cell.textLabel.text = expectation.expText;

    NSLog(@"TABLE VIEW EXPECTATIONS");
    return cell;
    }
    else
        return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{


    if (tableView == _listPersonTableView) {


        NSLog(@"Row In Person TableView Selected Nothing To Do HERE YET");


    }
    else if(tableView == self.listExpectationsTableView){

        NSLog(@"Row In Expectations TableView Selected Nothing To Do HERE YET");

    }else{
        NSLog(@"Do Nothing");
    }

}

编辑:所以从下面的评论我发现我的arrayOfExpectations是0但不知道为什么。请参阅下面的while循环。我知道它的循环两次,因为NSLog显示两次但是数组计数为0?

while (sqlite3_step(statement)==SQLITE_ROW){

                NSString *expText = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement,4)];

                NSString *expID = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement,3)];

                NSString *efeID = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement,0)];



                Expectations *expectations = [[Expectations alloc]init];
                [expectations setExpText:expText];
                [expectations setExpID:expID];
                [expectations setEfeID:efeID];

                [arrayOfExpectations addObject:expectations];
                NSLog(@"Expectations Count: %lu", (unsigned long)[arrayOfExpectations count]);

            }

2 个答案:

答案 0 :(得分:0)

我以前遇到过这个问题。这可能是由NSMutableArray未分配和初始化引起的。确保代码中的某处有arrayOfExpectations = [[NSMutableArray alloc] init];

答案 1 :(得分:0)

我曾经遇到过同样的问题。我检查每一件事,看看为什么表没有填充。我检查了UITableView的Delegate和DataSource是否已连接。数组中包含数据。并且每一件事都可以显示数据,但是徒劳无功。然后我只是尝试使用UITableViews的标签,我不知道它是如何工作的。它以某种方式工作。从那天起,我使用UITableView的标签,我从来没有回头。

你也可以试试。

if (tableView.tag == 1){
    ...Do something here...

}

尝试并检查。希望这对你有用,就像它对我一样。干杯。 :)

相关问题