2011-12-10 8 views
2

自分のプログラムでUITableViewを動的に作成しました。私は、この書いた.hファイルで手動でUITableViewを呼び出す方法

:didload方法で

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

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

self.view=aTableView 

と私が書いた外didload方法:.Mファイルで

UITableView *aTableView 

を私はこれを書いていますこれは:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [a count]; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *[email protected]"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をプログラム的に呼び出す必要があります。

どうすればいいですか?

+0

上記のコードはかなりプログラム的です。あなたが望むものを明確にすることはできますか? – bryanmac

+0

私はプログラムでテーブルを呼び出したい –

+0

デリゲートとデータソースを設定すると、プログラムでプログラムを呼び出しています。それからあなたを呼び戻しており、あなたはそれらのコールバックにプログラム的に答えています。あなたは本当にあなたがコールバックパターンを望まないと言っているのですが、行を設定することによってテーブルを '移入'したいのですか? – bryanmac

答えて

0

アプリ起動時にdidloadメソッドから呼び出す必要があります。

関連する問題