Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何手动调用UITableView_Objective C_Ios_Uitableview - Fatal编程技术网

Objective c 如何手动调用UITableView

Objective c 如何手动调用UITableView,objective-c,ios,uitableview,Objective C,Ios,Uitableview,我在程序中动态创建了UITableView 在.h文件中,我编写了以下内容: UITableView *aTableView - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [a count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellF

我在程序中动态创建了UITableView

在.h文件中,我编写了以下内容:

UITableView *aTableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [a count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier=@"Cell"; 

    static NSInteger StateTag = 1;
    static NSInteger CapitalTag = 2;
    static NSInteger StateTag1 = 3;
    static NSInteger StateTag2 = 4;


    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell == nil){
        cell=[[[UITableViewCell alloc]initWithFrame:CGRectZero  reuseIdentifier:CellIdentifier]autorelease];
        CGRect frame;
        frame.origin.x = 10; 
        frame.origin.y = 5;
        frame.size.height = 35;
        frame.size.width = 170;


        UILabel *capitalLabel = [[UILabel alloc] initWithFrame:frame];
        capitalLabel.tag = CapitalTag;

        [cell.contentView addSubview:capitalLabel];



        frame.origin.x += 175;
        UILabel *stateLabel = [[UILabel alloc] initWithFrame:frame];
        stateLabel.tag = StateTag;
        [cell.contentView addSubview:stateLabel];

        frame.origin.x += 180;
        UILabel *stateLabel1 = [[UILabel alloc] initWithFrame:frame];
        stateLabel1.tag = StateTag1;
        [cell.contentView addSubview:stateLabel1];


        frame.origin.x += 190;
        UILabel *stateLabel2 = [[UILabel alloc] initWithFrame:frame];
        stateLabel2.tag = StateTag2;
        [cell.contentView addSubview:stateLabel2];


    }
    UILabel *capitalLabel = (UILabel *) [cell.contentView viewWithTag:CapitalTag];
    UILabel *stateLabel = (UILabel *) [cell.contentView viewWithTag:StateTag];
    UILabel *stateLabel1 = (UILabel *) [cell.contentView viewWithTag:StateTag1];
    UILabel *stateLabel2 = (UILabel *) [cell.contentView viewWithTag:StateTag2];

    capitalLabel.text=[a objectAtIndex:indexPath.row];
    stateLabel.text = [b objectAtIndex:indexPath.row];
    stateLabel1.text = [c objectAtIndex:indexPath.row];
    stateLabel2.text = [d objectAtIndex:indexPath.row];


    return cell;
}
在.m文件中,我编写了以下内容: 在didload方法中

aTableView=[[UITableView alloc] initWithFrame:[[UIScreen mainScreen]applicationFrame] 
  style:UITableViewStyleGrouped];

aTableView.delegate=self;
aTableView.datasource=self;
aTableView.autoresizeSubviews=YES;

self.view=aTableView
在didload方法之外,我写了以下内容:

UITableView *aTableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [a count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier=@"Cell"; 

    static NSInteger StateTag = 1;
    static NSInteger CapitalTag = 2;
    static NSInteger StateTag1 = 3;
    static NSInteger StateTag2 = 4;


    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell == nil){
        cell=[[[UITableViewCell alloc]initWithFrame:CGRectZero  reuseIdentifier:CellIdentifier]autorelease];
        CGRect frame;
        frame.origin.x = 10; 
        frame.origin.y = 5;
        frame.size.height = 35;
        frame.size.width = 170;


        UILabel *capitalLabel = [[UILabel alloc] initWithFrame:frame];
        capitalLabel.tag = CapitalTag;

        [cell.contentView addSubview:capitalLabel];



        frame.origin.x += 175;
        UILabel *stateLabel = [[UILabel alloc] initWithFrame:frame];
        stateLabel.tag = StateTag;
        [cell.contentView addSubview:stateLabel];

        frame.origin.x += 180;
        UILabel *stateLabel1 = [[UILabel alloc] initWithFrame:frame];
        stateLabel1.tag = StateTag1;
        [cell.contentView addSubview:stateLabel1];


        frame.origin.x += 190;
        UILabel *stateLabel2 = [[UILabel alloc] initWithFrame:frame];
        stateLabel2.tag = StateTag2;
        [cell.contentView addSubview:stateLabel2];


    }
    UILabel *capitalLabel = (UILabel *) [cell.contentView viewWithTag:CapitalTag];
    UILabel *stateLabel = (UILabel *) [cell.contentView viewWithTag:StateTag];
    UILabel *stateLabel1 = (UILabel *) [cell.contentView viewWithTag:StateTag1];
    UILabel *stateLabel2 = (UILabel *) [cell.contentView viewWithTag:StateTag2];

    capitalLabel.text=[a objectAtIndex:indexPath.row];
    stateLabel.text = [b objectAtIndex:indexPath.row];
    stateLabel1.text = [c objectAtIndex:indexPath.row];
    stateLabel2.text = [d objectAtIndex:indexPath.row];


    return cell;
}
此表是自动调用的,我不想自动调用此tableview

我想以编程的方式调用这个tableview


我应该如何调用???

启动应用程序时,您必须从didload方法调用它。

启动应用程序时,您必须从didload方法调用它。

上面的代码非常有程序性-您能澄清您想要什么吗?我想以程序性方式调用表您在设置委托和数据源。然后它会给你回电话,你会以编程的方式回答这些回电话。你真的是说你不想要回调模式,而是想通过设置行来“填充”表吗?上面的代码很有程序性-你能澄清你想要什么吗?我想通过编程调用表你在设置委托和数据源时通过编程调用它。然后它会给你回电话,你会以编程的方式回答这些回电话。您真的是说您不需要回调模式,而是希望通过设置行来“填充”表吗?